I have a problem with the mysql_query() function...
Consider the following code:
<?php
$db = mysql_connect("host", "user", "pass"
$connect = mysql_select_db("webdemo",$db);
$query = "SELECT COUNT(*) AS myCount, userType FROM survey GROUP BY userType";
$result = mysql_query($query, $db);
// DEBUGGING CODE:
printf ("<h3>Debug Results:</h3>"
printf ("db = $db <br>"
printf ("connect = $connect<br>"
printf ("query = $query<br>"
printf ("result = $result<br>"
if(mysql_num_rows($result) >0) {
while($myrow = mysql_fetch_row($result)){
printf($myrow[myCount], $myrow[userType]);
}
} ELSE {
print "<BR>ERROR: There are no rows!";
}
?>
When I run this, I get:
---
Debug Results:
db = Resource id #1
connect = 1
query = SELECT COUNT(*) AS myCount, userType FROM survey GROUP BY userType
result =
Warning: Supplied argument is not a valid MySQL result resource in c:/program files/abria merlin/apache/htdocs/report.php on line 25
ERROR: There are no rows!
---
Any ideas what can be causing this? The user in this case has both SELECT and INSERT privs in the mysql:user table, and can successfully insert new rows via another script...
I can successfully run the SELECT stmt in the mysql console and get the results that I want, so I'm satisfied that the SELECT is OK.
HELP!
Consider the following code:
<?php
$db = mysql_connect("host", "user", "pass"
$connect = mysql_select_db("webdemo",$db);
$query = "SELECT COUNT(*) AS myCount, userType FROM survey GROUP BY userType";
$result = mysql_query($query, $db);
// DEBUGGING CODE:
printf ("<h3>Debug Results:</h3>"
printf ("db = $db <br>"
printf ("connect = $connect<br>"
printf ("query = $query<br>"
printf ("result = $result<br>"
if(mysql_num_rows($result) >0) {
while($myrow = mysql_fetch_row($result)){
printf($myrow[myCount], $myrow[userType]);
}
} ELSE {
print "<BR>ERROR: There are no rows!";
}
?>
When I run this, I get:
---
Debug Results:
db = Resource id #1
connect = 1
query = SELECT COUNT(*) AS myCount, userType FROM survey GROUP BY userType
result =
Warning: Supplied argument is not a valid MySQL result resource in c:/program files/abria merlin/apache/htdocs/report.php on line 25
ERROR: There are no rows!
---
Any ideas what can be causing this? The user in this case has both SELECT and INSERT privs in the mysql:user table, and can successfully insert new rows via another script...
I can successfully run the SELECT stmt in the mysql console and get the results that I want, so I'm satisfied that the SELECT is OK.
HELP!