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
42
Other forums
Blogging s/w
heya frndz!!! i want to start a blog.... m looking for a s/w like oscommerce which is thr for e-comm
Upload Code Help
Hi everyone I need some help with a bit of code ive been working with for a while. I am completely s
Export hangs
Hi all, please help
I have a Oracle 10.2.0.3.0 database. When I want to query the dba_segmen
Looping Problem
I've got a client that has a database with about 200 events at any given time. I'm trying to loop t
Call db table from any PHP file
Hi,
I want to be able to call a database table that will be setup in another file called init
Access website from only 1 computer...?
One of my customers wants his website to only be accessed by people in which they bought the website
Solution Manager BPR
Does the SolMan-BPR-ARIS-Integration (http://www.ids-scheer.com/en/ARIS/ARIS_Platform/ARIS_Business_
Hits this week counter
I have a counter on my site that tracks hits, IP's, etc. into a mySQL database. It also includes the
Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is
HeaderSelectedCssClass not working
I have an accordian where I have a drop down list in the first pane and a grid in the second pane.