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

Change snippet to use CURDATE
I am using time() in the snippet below, I would like to use CURDATE() and have the database setup fo

Getting the full city list from maxminds geoip database
I am suprised I can't find any references to this.

I have maxminds geoip lite installed and i

mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty

gettext translates ALWAYS?
I'm using gettext with the new version of XAMPP (5.3.0) on Windows Seven RTM (build 7600)
gettext

using file_get_contents??
okay how would i create a script using file_get_contents() in php have it grab search pages 1-20 and

Switch letters in message (basic cryptology)...
I am trying to switch letters around in a message for an application on my site (see here). The prob

Error when call dll from oracle
Hi all, please help me!

I have dll write C language, I want call it from oracle procedur

Convert array to string and write to csv file
I am looking to write a MySQL query to a csv file.

At the minute I:

check for the orig

change text color with a jQuery code
Hihow can I change the text in a asp:TextBox to a different color when I start typing using jQuery?I

Random date selection
i want to select random date with time(hour+minutes+sec) where date is specified(10/22/2009) and tim

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