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
Consuming MII WebService in Java WebDynpro
Hello,
We are facing a strange situation...
We define a transaction in MII to
Transport data between itab and textfield on ALV event
Hallo,
I have a ALV Grid ( cl_gui_alv_grid ) and I also have hotspot click event with a h
Gantt Chart Tool
Does anyone know of a good free gantt chart creator tool
Thanks
Big Problem!! Please help
Hi Guys,
Im making a website for a friend have encountered a really annoying problem. When ev
Securing a user input - need some confirmation
Hello All,
I am in the process of recoding a large proportion of an e-commerce site, one of t
Problem writing URL into database
How would I write this into the database?
<?php echo "http://".$_SERVER['SER
Revoking alter any table from a schema
Hi All,
i am working in Oracle 10g.
my requirement is to revoke all kind of DDL oper
Error with Font and imagettfbbox
I keep getting an error that says "Warning: imagettfbbox() [function.imagettfbbox]: Could not f
List/Menu Box
On an edit page when you want something to select what a user has previously selected from the datab
Force download script not handling files with spaces properly
I have a regular old php force download script, uses this code:
Code: header("Cache-Cont