What's the difference here????

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi gang

I ran into a minor, but weird problem yesterday ...

Query one:

$catpermsquery = mysql_query("SELECT cat_view FROM hf_category_perms WHERE `catID`='$catID' AND `levelID`='$levelID' LIMIT 1") or die('Could not get cat perms'.mysql_error());
$catperms = mysql_fetch_array($catpermsquery);
$cat_view = $catperms['cat_view'];



$perms = mysql_fetch_array(mysql_query("SELECT may_view FROM hf_level_perms WHERE `forumID`='$forumID' AND `levelID`='$levelID' LIMIT 1")) or die('Unable to get perms<br>'.mysql_error());
$may_view = $perms['may_view'];



Both queries are on the same page ... the first one makes the script determine whether or not to run the query that generates the loop where the second query is inside ...


If I write the first query like the second one:

$catperms = mysql_fetch_array(mysql_query("SELECT cat_view FROM hf_category_perms WHERE `catID`='$catID' AND `levelID`='$levelID' LIMIT 1")) or die('Could not get cat perms'.mysql_error());

Then all it displays is my error message: Could not get cat perms ... and no MySQL error message. I cut it up like above, and it works fine.

All I really wonder about is WHY it behaves like this in one query, but not the other....

the two tables that are used in here have similar structure, one primary key, ID, that's merely an auto-increment that I don't use for anything but the required indexing, then catID in the first table, forumID in the second, and levelID in both. For each combo of levelID and catID/forumID there's 1 row in each table. The only structural difference is that the second table has 10 more fields than the first one...

This is the only time I've had a problem with putting mysql_fetch_array(mysql_query()) inside each other ... some of the queries I naturally have to split because I need to check if there's any result returned from the query ... but with these perms query the data they look for will always exist (unless MySQL makes a mistake and dumps a row without being told to), because they're only run inside other queries that look for the respective catID/forumID these uses, so they won't be called unless that particular category/forum exists. So there shouldn't be a problem combining the two statements into 1 ... (other than it not exactly being textbook coding :p )


TIA


Rene
--
Rene Brehmer
aka Metalbunny

http://metalbunny.net/
References, tools, and other useful stuff...

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux