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
Functions Not Loading Into Div
I had some help doing some of this but what I'm trying to do is get my functions to retrieve its val
Handling text changed in text box control using Ajax
I need to create a web form with a text box control. When someone types text into the textbox I nee
help with contest script
I would like to code a contest script to my site but i don't know how. Could someone just give me pu
Table control is disappearing from Screen
Hi Experts,
I have a screen with multiple table control(TC). Each table control has two c
Filling gaps in dates
So i'm doing a query for sales data and my return array looks like this
('date' => '20
Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t
Strange PHP/mySQL error ... am I just tired?
Code: <?
## CONNECT TO DB FUNCTION!
function ConnectTo($db2con)
{
$hostNam
Text to picture Generator
Hello, i have found this script and it works really good^^ But i have one problem, i would like to c
foreach result into a single variable
Hi,
I have this code...
Code: [Select]foreach ($_POST['Interests'] as $interest =&
SCRIPT ERROR
Here is the CONTACT FORM I made for our website:
<form id="form1" name="