RAND() with a generated link I have a project from my college. I'm making a site which will display different quotations each time the page is loaded. I use the following code:

$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xlsx_db", $con);

$result = mysql_query("SELECT * FROM sheet1 ORDER BY RAND() LIMIT 1");

if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}

$row = mysql_fetch_array($result);
echo "&lt;b&gt;Quote: &lt;/b&gt;";
echo $row['quote']."&lt;br&gt;";
echo $row['by']."&lt;br&gt;";
?&gt;


All works fine. But my teacher told me to make the text link-able. So that if anyone copy that link of the quote, that case, he can pest the code on the browser and can see that quote again.

Could anyone please help me with this task? Any kind of help is really appreciated.
Your link should look like this:

&lt;a href="http://www.yoursite.com/quotes?q_id=123"&gt;Permalink&lt;/a&gt;


In your php code, you can grab the selected quote id like this:

$q_id = $_GET['q_id'];


To check if the q_id has been set:

if (array_key_exists('q_id', $_GET)) {
    // the q_id was specified
}


To check that the q_id is numeric (important to do before plugging it into a mysql query):

if (is_numeric($_GET['q_id'])) {
    // q_id is a number
}


To fetch that single quote:

$result = mysql_query("SELECT * FROM sheet1 WHERE q_id = " . $q_id);


Deprecation of mysql_ functions


  PHP functions that start with mysql_ have been deprecated as of PHP 5.5.0. If you are in a position to do so, please consider updating your code to use the MySQLi or PDO extensions instead.