I have made a form that asks the user to put in first name and last name and stores it in MySQL database
Now in another file i want to use the database in the table randomly
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT `column` FROM `table` ORDER BY RAND() LIMIT 1");
//what should i write here if i want get the randomly selected row data in the following variable
//$firstname = " ";
//$lastname = " ";
mysql_close($con);
?>
basically i want $firstname $lastname to get values randomly from MySQL table and at the same time belong to same row
You’re nearly there – the query is already set up correctly to retrieve 1 random row from the table. You just need to specify which columns to retrieve, and call
mysql_fetch_*()on the result to populate your variables: