title: Using PHP to pull data from MySQL table column randomly
body: <p>I am using the following (assume I already plan to change these to mysqli at a later date and am aware of the insecurity of the queries used), to pull text strings from rows in one column in a MySQL table and the output in a browser would, ideally, be a randomly selected string from this column:</p>
  
  <pre><code>mysql_connect($host,$username,$password); 
  mysql_select_db($database) or die(mysql_error ()); 
  
  $query="SELECT * FROM `tablename` ORDER BY RAND() LIMIT 0,1;";
  $result=mysql_query($query);
  $rows = array();
  while($row = mysql_fetch_array($rs)) {
  $rows[] = $row;
   }
  mysql_close();
  $max = count($rows) - 1;
  </code></pre>
  
  <p>Using the following echo line to achieve the last bit  in the browser:</p>
  
  <pre><code>echo $rows[rand(0, $max)][0] . " " . $rows[rand(0, $max)][1] . " " . $rows[rand(0, $max)][2] . " " . $rows[rand(0, $max)][3] . " " . $rows[rand(0, $max)][4]$
  ?&gt;
  </code></pre>
  
  <p>I receive the error "PHP Notice:  Undefined offset: 0 in script.php on line 19" in reference to this echo line (which, admittedly, was pieced together from other threads and tutorials, so I do not follow completely), however, I've since resolved all other errors logged and observed, so if possible, how can I amend this so the output is just a single row (the text within it) from the column?</p>