title: Assign MAX value of mysql field to php variable
body: <p>I want to assign the max value of a column in mysql to a variable in PHP. This ultimately will be to validate form data. Having trouble as I am new to PHP.</p>
  
  <p>Tried this:</p>
  
  <pre><code>$result = mysql_query("SELECT MAX(receipt_id) FROM receipts");
  if (!result) {
  trigger_error(mysql_error($result));
  }
  
  $row = mysql_fetch_assoc($result);
  $maxid = $row["receipt_id"];
  
  echo "The max id is $row";
  </code></pre>
  
  <p>(The echo is just for testing). In this case the result was:</p>
  
  <p>The max id Array</p>
  
  <p>When I echo the $maxid variable in the above code there is no value returned in the echo.</p>
  
  <p>And with this code:</p>
  
  <pre><code>$result = mysql_query("SELECT MAX(receipt_id) FROM receipts");
  if (!result) {
      trigger_error(mysql_error($result));
  }
  
  echo "The max id is $result";
  </code></pre>
  
  <p>I get:</p>
  
  <p>The max id is Resource id #2</p>
  
  <p>What am I missing here?</p>
  
  <p>Thanks in advance!</p>