Single MySQL Result


/ Published in: PHP
Save to your folder(s)

Simple but useful function for getting a single piece of data from a database and placing it straight into a variable.

Example:
$variable = one_result("SELECT columnOne FROM table WHERE columnTwo=whatever");

This would insert the value of columnOne where columnTwo is 'whatever' into $variable


Copy this code and paste it in your HTML
  1. function one_result($query) {
  2. $result = mysql_query($query);
  3. $row = mysql_fetch_row($result);
  4. return($row[0]);
  5. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.