Please help the newbie!
I'm collecting the responses to a very simple survey form as text strings in a VARCHAR field in a table.
I can run the following SELECT statement on the console and get exactly the response I need:
SELECT COUNT(userType) AS myCount, userType FROM survey GROUP BY userType;
However, when I place this SELECT statement into my PHP page, I get the dreaded "Supplied argument is not a valid MySQL result resource" message. Here is my PHP code:
<?php
$db = mysql_connect("localhost", "user", "passwd");
$connect = mysql_select_db("webdemo",$db);
$query = "SELECT COUNT(userType) AS myCount, userType FROM survey GROUP BY userType";
$result = mysql_query($query);
while($myrow = mysql_fetch_row($result)) {
printf($myrow[0], $myrow[1]);
}
?>
The line that the error is reported on is the WHILE() line. If I replace the WHILE statement with "echo $result;" I don't get any sort of return or error message.
Help!