How to display random record from table?


Posted on 16th Feb 2014 07:03 pm by admin

I have the following code:

Code: <?php
$display_block .= "<input type=button value="Generate Random Monster">";
Did you know?Explore Trending and Topic pages for more stories like this.

$get_monsters = "select * from monsters1";
$get_monsters_res = mysql_query($get_monsters, $conn) or die(mysql_error());

$display_block .= "<table class=monster>";

while ($monsters_info = mysql_fetch_array($get_monsters_res)) {
$monster_id = $monsters_info['id'];
$monster_name = $monsters_info['name'];
$monster_map = $monsters_info['map'];
$monster_location = $monsters_info['location'];
$monster_hit_points = $monsters_info['hit_points'];
$monster_attack = $monsters_info['attack'];
$monster_defense = $monsters_info['defense'];
$monster_agility = $monsters_info['agility'];
$monster_wisdom = $monsters_info['wisdom'];
$monster_magic_endurance = $monsters_info['magic_endurance'];
$monster_number_of_attacks = $monsters_info['number_of_attacks'];
$monster_range = $monsters_info['range'];
$monster_experience_points = $monsters_info['experience_points'];
$monster_silver = $monsters_info['silver'];

$display_block .= "<tr><td>$monster_name</td>";

}
?>

And what I want to do is when they click the button (Generate Random Monster), that it displays a random record from the table. All I want the user to see is the "monster_name". Can anyone tell me how to make the button show a random record from the table in my database? I also would like the table information to be invisible to the user until they click the button. How can I do that?
No comments posted yet

Your Answer:

Login to answer
145 Like 42 Dislike
Previous forums Next forums
Other forums

Company Code for Vendors created through Business Partners
Hi, experts!

I'm trying to set up the integration between Business Partner (BP) and Vendo

have trouble in a if condition
The if below is working ok, it check when indexes, name, zipcode and state are empty.
Code: &

Word filter problem
Hello,

im trying to make a filter for words inputted in to my website but i want to store the

Problems with returning true or false in eval()'d code
Hi guys,

Would appreciate some help with a problem when running eval() on a function that sho

Sending UDP Raw socket
I truly need help on this. I am trying to write a test program that simulate a network environment

Record count of entire database
Does anyone know if there is a way to obtain the number of records in each table of the database usi

$variable $variables type question
I need to be able to designate an array element dynamically, so I thought to use a variable variable

Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.
Some code runs as perfectly valid code,

PHP - HTML
Could anyone give me some GOOD sample links for php - html email tutorial.

Thanks!

rename the file
File.txt

Code: ***DOCUMENT***
..DN:
000044255
..CB:
..SN:
..PY:
2009
..E

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash