RE: [PHP-DB] must I "while" loop
| From: | Emil Rasmussen | Date: | Mon, 12 Mar 2001 15:05:01 +0000 |
| Subject: | RE: [PHP-DB] must I "while" loop | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-7330@lists.php.net to get a copy of this message | ||
Hi
> OK, if I am extracting a row from a mysql DB where I know
> that there is only ONE row:
>
> $result = "SELECT company, fname, lname FROM table_name WHERE
> id = \"$id\"
> ";
<snip>
> So my question, shouldn't I be able to use the variables
> $company $fname $lname before the WHILE loop since I know
> that there is only one record?
You have to make use of the mysql_result() function, the code would look
something like this:
$result = mysql_query("SELECT company, fname, lname FROM table_name WHERE id
= '$id'");
$company = mysql_result($result,"0","company");
$fname = mysql_result($result,"0","fname");
$lname = mysql_result($result,"0","lname");
Emil
--
Emil Rasmussen
http://www.noget.net