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
Splitting Attributes
SQL> SELECT I_NAME, substr(I_NAME,1,instr(I_NAME,'O')) "First part",
substr(I_NAME, IN
restricting another login once you logout
Hello,
how can I restrict a page from login authenticating against info in a MySQL DB for a s
This must be easy , pulling the last record of the day, every day, from a txt
I have a txt file logging weather data every minutes (so 1 record per minute). I want to extract the
Help Import Animoto and Youtube
CAn someone help me urgently want to allow users on my website to import youtube/revver/dailymotion
ScriptResource.axd gives an error on fresh install of ASP.NET Ajax 1.0
Hello,I have a fresh install of Microsoft ASP.NET Ajax 1.0. When I create an Ajax enabled website in
php title problem
Hi,
I am having a problem managing my page title with PHP.
Currently I have my <
BackButton Behaviour in AJAX
I have an ASPX Page AJAX Enabled!The page has a gridView and a DDL for filtering on it. The Gridview
Please Help my PHP Dating Function.
Hi everyone!
Well here is my code that displays this:
It works wonderful.
IIS7 and getimagesize() problem
I have just discovered after hrs of trying to fix a problem where it's coming from. It's to do with
PayPal Redirect Issue
When I have my paypal button set so that is redirects to http://empiremarketing.ca/order.php,it work