best way to tell is to place .....'or die(mysql_error())' after any call to mysql_query() to see what mysql is complaining about. personally I sometimes declare the query first so i can echo that as well after the msyql_error() function, so i can see the query that has just been excecuted. helpful with dynamic queries. $qry = "SELECT * FROM $tableName where $fieldName='$fieldValue'"; $result = mysql_query($qry, $conn) or die(mysql_error() . $qry); hth jeff "Mike Klein" <mikeklein@ieee.o To: php-db@lists.php.net rg> cc: Subject: Help needed with variable scoping? or mysql problem 08/14/2003 08:58 AM I've been using JSP for some time now, and thought I'd write a couple of rdbms explorers (flat tables, simple master/detail paradigm) using other technologies, like PHP, Cocoon, etc. Well...it's been fun. I have more working than not. But now I am hung up. I am getting wierd results in a php script when I simply change the order of some mysql calls. I'm using php-4.3.2, rh9, and mysql 3.23. My error is the following (the first line above the Warning below is a dump of parameters to the showMaster function which is what's bombing): conn=Resource id #3 databaseName=info tableName=movies fieldName=title fieldValue=36th Chamber Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /foo/bar/mywebsite/private/database.php on line 107 Line 107 is the <first> mysql_num_rows call below. function showMaster($conn, $databaseName, $tableName, $fieldName, $fieldValue) { echo "conn=$conn\n"; echo "databaseName=$databaseName\n"; echo "tableName=$tableName\n"; echo "fieldName=$fieldName\n"; echo "fieldValue=$fieldValue\n"; ========This code fails when placed here========== $result = mysql_query("SELECT * FROM $tableName where $fieldName='$fieldValue'", $conn); $numRows = mysql_num_rows($result); if(mysql_num_rows($result) == 1) { showDetail($conn, $databaseName, $tableName, $fieldName, $fieldValue, $result); exit; } echo "numRows=$numRows\n"; ======================================== $fields = mysql_list_fields($databaseName, $tableName, $conn); $numFields = mysql_num_fields($fields); echo "<TABLE border=1 width=100%>\n"; echo "<tr>"; for($i = 0; $i < $numFields; $i++) { printf("<td>%s</td>", mysql_field_name($fields, $i)); } echo "</tr>"; ========The SAME code succeeds when placed here!!!!!========== $result = mysql_query("SELECT * FROM $tableName where $fieldName='$fieldValue'", $conn); $numRows = mysql_num_rows($result); if(mysql_num_rows($result) == 1) { showDetail($conn, $databaseName, $tableName, $fieldName, $fieldValue, $result); exit; } echo "numRows=$numRows\n"; ======================================== while($myrow = mysql_fetch_array($result)) ...rest of method... } Any ideas on why this is? When I move the lines above (from $result=...to...echo 'numRows') down a few lines to just before the mysql_fetch_array, then everything works. Whazzup?!? mike klein -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php