A
Anonymous
Guest
sjbt said:Can someone tell me why I get a response of
"Resource id #3"
from the following code? -- and should I be using echo or printf to return results?
Code:<?php // ... $result = mysql_query("SELECT * FROM database.table") or die("Invalid query: " . mysql_error()); echo $result; ?>
That would be because you're trying to echo a result resource. A quick glance at the documentation will tell you that mysql_query() doesn't return a string or an int or anything particularly easy to print -- it returns a resource, which is an internal PHP construct that's not intended to be printed -- it's intended to be passed to a function like mysql_fetch_row() or mysql_fetch_assoc().
By the way, you shouldn't be using printf() to echo a simple string unless you're doing some fancy formatting. This is one of the Top 21 PHP programming mistakes. Just use echo or print.