Click to See Complete Forum and Search --> : Getting data from a database...


Brendan Nolan
12-22-2002, 08:26 PM
I am trying to get data back out out of a database in the following way....

$sql = "SELECT * FROM tablename WHERE id='$id'";
$result = mysql_query($sql);
$something = mysql_result($result,"field-name-i-want");
echo "$something";

But for some reason it only ever returns the first field in the table as opposed to the "field-name-i-want"

WHY????

The "printf" thing works fine, but I want it in a variable!!

Brendan Nolan
12-22-2002, 09:54 PM
Okay I have it... but just so that if anyone else finds themselves in the same position then here it is...

$myrow = mysql_fetch_array($result);
$something = mysql_result("thing-i-want");