Arch Stanton
04-30-2004, 11:22 AM
Here is something I've been doing lately. When querying one record, I use this shortcut to take each field and convert it to a variable using the extract command and mysql_fetch_array. so rather than retrieve each value like this . . .
$myArray[fieldName]
You can use this:
$fieldName
So here it is:
$sql = "SELECT * FROM `tableName` WHERE `id`='$id';";
@extract(mysql_fetch_array(mysql_query($sql)));
Notice I used the @ to supress error messages, this sometimes spits them out for reasons I can't figure out. That being said, there is probably someone out there who will say this is not the proper way to do this.
There is a bit of a longer way to do it as well:
$sql = "SELECT * FROM `tableName` WHERE `id`='$id';";
$query = mysql_query($sql);
$array = mysql_fetch_array($query);
@extract($array);
Well, there it is.
More Info: http://ca2.php.net/manual/en/function.extract.php
$myArray[fieldName]
You can use this:
$fieldName
So here it is:
$sql = "SELECT * FROM `tableName` WHERE `id`='$id';";
@extract(mysql_fetch_array(mysql_query($sql)));
Notice I used the @ to supress error messages, this sometimes spits them out for reasons I can't figure out. That being said, there is probably someone out there who will say this is not the proper way to do this.
There is a bit of a longer way to do it as well:
$sql = "SELECT * FROM `tableName` WHERE `id`='$id';";
$query = mysql_query($sql);
$array = mysql_fetch_array($query);
@extract($array);
Well, there it is.
More Info: http://ca2.php.net/manual/en/function.extract.php