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
42
Other forums
simple php table loop
Hi all,
I've the following code
<?php // Create category options
if description does not contain the following words
Hello everyone,
I am parsing a MS Excel (.xls) file and adding it's content to a mySQL databa
Page doesn't expand for content
Hi. I've been testing a query I made. It's here http://lapr1.6te.net/inquerito.php
The page doesn
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
batch file not building to webapps folder
Hello. I just started running Vista :P and can't seem to get my projects deployed. I found out how
Spaghetti Code
So.
I've pretty much reached the point where I have so many isset s on one page that I can't
Image upload - determine folder
I have an upload script that may be accessed from different directories. Problem is, the script is m
Price in PR
Dear Experts,
Why we have to enter the price in the PR, and why there is no free goods indicato
Product categories for registration
Dear all,
We are going live with the Supplier registered next week. At standard, the 'sel
Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi