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">";

$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

Help with lottery style system?
I'm working on a currency system for forums and it is going to have a type of lottery system built i

Time script, set to my time zone?
I am using this line to get the date and time

Code: $time = date(F." ".d.", &q

Different actions for different parts of a string
<?php
function dosomething($string, $else = '') {
if (empty($else))
$string

Open/Close Links in Php
Hello, Hoping someone can inform me how I can get PHP to automatically open a set of links in a new

having probem inserting data into db table
hi

i have a table with following columns in it
Code: candidate_id, degree, cgpa, institute

PHP & Java
Hello,

can PHP code be used inside java code?

Code: [Select]<SCRIPT LANGUAGE=&q

Floating Point Precision Loss
I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D

Is it a good practice to store user info. in sessions?
I am making a user class for my script which stores all the user information in sessions. It takes u

Problem with Subscreen
Dear Experts ,
I am facing a problem with the subscreens. My senario is as follows :

small inaccuracies
I have this code to convert fractional base 10 into base 2:

while($num > 0)

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