Oh yeah that's the ticket!
I'd forgotten that I'd removed the mysql_select_db statement when doing
some earlier 'cleanup'. It just so happens that a few of the mysql metadata
calls (like listing fields/etc.) were inadvertently setting the db...but
only for a brief period of time...wierd.
As I mentioned, I just started using php yesterday, so I'm still learning
some tips/tricks.
But...to php's credit, I gotten a fairly functional rdbms
explorer/browser/editor going in under a day. I had initially planned on
'hardcoding' some rdbms master/detail forms, but after doing just one of
them, and seeing the plethora of mysql calls available, I decided to
genericize the code, and now it's a general explorer/etc. for all of my
databases. Seems pretty speedy too.
Now I just need to add result set 'scrolling'. Returning 2000 records is not
nice...
thanks buddy...
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 14, 2003 8:10 AM
To: Mike Klein
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Help needed with variable scoping? or mysql
problem
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
[EMAIL PROTECTED]To:
[EMAIL PROTECTED]
rg cc:
Subject: [PHP-DB] 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