Jump to content

Efficient way of pulling single value from a database??


xProteuSx

Recommended Posts

Right now I am using code such as this:

 

$query = "SELECT somevalue FROM sometable WHERE id=1"

$result = mysql_query($update) or die ('Error in query: ' . mysql_error());

 

$somevalue = '';

 

if (mysql_num_rows($result) == 1)

  {

  while($row = mysql_fetch_assoc($userstatsresult))

    {

    $somevalue = $row['somevalue'];

    }

  }

 

echo $somevalue;

 

Is there a short-hand method to get that single value without the IF/WHILE stuff?

#1

 

<?php
    $query = "SELECT something FROM sometable WHERE ID = 1";   
    $result = mysql_query ($query);
    $row = mysql_fetch_array($result);
    $record = $row[0];
?>

 

#2

 

<?php
    $sql = "SELECT something FROM sometable WHERE ID = 1";
    $email = mysql_result(mysql_query($sql), 0, 0);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.