...

View Full Version : echoing a MySQL field



Democrazy
09-11-2011, 01:53 PM
How can I echo a field from a MySQL database in PHP?


+----+---------------+------------+---------+-------+-------+-------+--------+----------+
| id | primarycolour | pricerange | country | sizes | sizem | sizel | sizexl | category |
+----+---------------+------------+---------+-------+-------+-------+--------+----------+
| 1 | Black | 1 | Italy | 2 | 1 | 1 | 3 | Belts |
| 2 | Blue | 2 | USA | 1 | 0 | 0 | 2 | Belts |
+----+---------------+------------+---------+-------+-------+-------+--------+----------+

For example, how would I echo the country field for id 2?

tangoforce
09-11-2011, 02:07 PM
$Query = "select country from <tablename> where id='2'";

$Result = mysql_query($Query);

$Row = mysql_fetch_array($Result);

print $Row['country'];


You could also use mysql_result to simplify things but its been a while since I've used that and frankly I can't remember how to.

Democrazy
09-11-2011, 03:15 PM
Hey tangoforce, the code worked so I'd like to publicly thank you.

Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum