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

extract data
Code: <div class="post hentry uncustomized-post-template">

pls clear my confusion
Hi friends,

Pls solve my query .

what is the exact use of Scope Resolution Operator( i

quotes changing
hi all

in my content

opening quotes " changes to “

close qu

Is STL important?
I'm just starting programming and I've made it until the Standart Template Library. But the chapter

close site for maintenance
i get a tutorial, saying the following code can put our site offline, and only the developer can vie

Working with popups and such in a class
I've recently started building my applications completely enclosed in classes. I like the fact that

Problems with strings containing
Hey all,

I have encountered something strange in a script. I am trying to write an XML heade

Simple image grab script.
I was wondering if it was possible and if anyone knew how to make a simple php script that looks at

disable all input buttons
Hello Friends,

suppose i do have a file ( file.php ) has a submit button

Code: [Sele

creating a 1 to 100 in a table
hi guys I am a newb in php need some help.

I have a table with 1 column and 100 rows and in

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