Posted By

iridium on 01/03/09


Tagged

mysql result single


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jeremyhcobb
umang_nine
mgerdt


Single MySQL Result


 / Published in: PHP
 

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

  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
Posted By: MMDeveloper on February 20, 2009

wouldn't that only return the first column of the first result? Or is that what you wanted it to do?

$row = mysqlfetchrow($result); would set $row to all the values of the first result and $row[0] would just be the value of the first column of the first result.

You need to login to post a comment.