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
PHP Code / Script To check weather the given email exists in a domain
Hi,
I want to implement the following in my web page
in sign up we will ask to enter u
disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte
JQuery, Masterpage, and Control issue
Hey everyone, I am using JQuery in several sites so I thought it would be best to place the library
asp authentication problem
Hello all,
I want to use the asp authentication (from asp.net configuration) in my web site. there
How to replace search button with link?
hi to everbody.
i have a search submit form and button like this :
<form id="f
Scene graph using Direct3D?
There are several C++ scene graph based packages available for OpenGl, like say OSG,
http://w
MS Access data into a html table
Hi everyone, I am quite a novice at php but I have created some helpful scripts that fetch data
f
A Few Questions
Hi, I want to ask a few questions that I can't seem to find..
1) I'm creating a "shortcu
How to insert random unique values in 2 columns ?
I have table with 2 columns
Create Table code_for_code (
first_code varchar2(10) uni
present value of sequence?
Hi
Please help me to find out the present value of sequence?
Thanks