Re: echo
| From: | Richard Lynch | Date: | Fri, 03 Aug 2001 22:19:04 +0000 |
| Subject: | Re: echo | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-61200@lists.php.net to get a copy of this message | ||
> $sql = "SELECT first_name, last_name, address, state, zip_code, country,
> company, occupation, telephone, fax, email, entry_name, password, package,
> registration_date, valid_until, max_users
> FROM $table_name
> WHERE uid = \"$uid\"
> ";
>
> $result = @mysql_query($sql,$connection) or die("Couldn't execute
query.");
>
> -----------When I echo $sql, I get this result
> -----------SELECT first_name, last_name .......
> How can I echo the actual values?
$sql is the QUERY (question) you send to the database.
$result is a "ticket number" (like a number at the meat counter in the deli)
to the RESULT SET (answer) from the database.
So, echo $sql is good to make sure you are asking the question properly, but
not much else.
You'll need to "present" your $result ticket to MySQL functions to get your
data out:
while ($row = mysql_fetch_array($result)){
$first_name = $row['first_name']; # Or could use 0 instead of
'first_name'
$last_name = $row['last_name']; # Or could use 1 ...
.
.
.
echo "$first_name, $last_name, ...<BR>\n";
}
Since you'll do this a lot, here's a short-cut:
while (list($first_name, $last_name, ...) = mysql_fetch_row($result)){
echo "$first_name, $last_name, ....<BR>\n";
}
The mysql_fetch_row and mysql_fetch_array functions return each row, one by
one, in slightly different array formats.
The list() construct above "de-constructs" the array format returned by
mysql_fetch_row() to turn the array of one row into individual variables.
http://php.net/mysql_fetch_row
http://php.net/mysql_fetch_array
--
WARNING richard@zend.com address is an endangered species -- Use
ceo@l-i-e.com
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm