View Full Version : problem with printing out results from mysql

04-30-2004, 04:13 AM
$Link = mysql_connect ($Host, $User, $Password);
$Query = "SELECT * from $TableName";
$Result = mysql_db_query ($DBName, $Query, $Link);

if ($Result) {
print ("The query was successfully executed!<BR>\n");
while ($Row = mysql_fetch_array($Result)) {
print ("$Row[Products]");
} else {
print ("The query could not be executed!<BR>\n");
mysql_close ($Link);

I'm getting The query was successfully executed! printed out on the page so I'm assuming it found the database and table correctly? What I'm trying to do is grab every Record set's text that is in the products column. I think the syntax is correct because I'm not recieving any syntax errors. The problem I'm having is with printing out the results it found. It's just not printing anything out. Can anyone help me?

I put an echo under print ("$Row[Products]"); to print out Row and it printed out 13 times which is how many rows I have in that table. So now I def know my query is right. Now I'm just stuck on how to print out the text that is in the Product column.


04-30-2004, 04:37 AM
Nevermind I figured it out. where it says: print ("$Row[Products]"); I typed Products instead of Product. Product is the correct column name.


04-30-2004, 09:41 AM
glad you got it sorted , quick note though ...

technically $Row[Product] is incorrect,it should be $Row['Product'] as $Row[Product] & $Row['Product'] could mean 2 totally different things if `Product` was a constant (http://www.php.net/constants).

also (and this is just coding preference & no more than that ), most peeps would use echo() over print();

echo $Row['Product'];