Farelski Posted April 5, 2011 Share Posted April 5, 2011 For some odd reason this snippet of code gets a boolean false returned for my variable $result on the last query. If i remove the JOIN conditions (ON temp.gid=g.group_id;) it works fine but will not work with those in place. I've had it print out all of the SQL queries and I've executed them on phpmyadmin all at once and they work fine/return the correct results. Any idea why this is failing on the PHP side? Any help would be greatly appreciated!!! MYSQL Version: 5.1.41 $query = "CREATE TEMPORARY TABLE temp (gid int(11));"; mysql_query($query); $query = " INSERT INTO temp (gid) SELECT group_id FROM group_connections WHERE user_id='$user_id' AND pending='0';"; mysql_query($query); $query=" SELECT group_id as id, group_picture as picture, group_name as name FROM groups as g JOIN temp ON temp.gid=g.group_id;"; $result = mysql_query($query) or ( "Error " . mysql_error () ) ; $info=array(); $i = 0; while($row = mysql_fetch_array($result)) { $info[$i]['group_id'] = $row['group_id']; $info[$i]['picture'] = $row['picture']; $info[$i]['name'] = $row['name']; $i++; } $query = "DROP TABLE IF EXISTS temp"; mysql_query($query); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 5, 2011 Share Posted April 5, 2011 That's because you are or'ing a string with the mysql_query() returned value. I suspect you meant to use or die(....) on the line after your mysql_query() statement. Quote Link to comment Share on other sites More sharing options...
Farelski Posted April 5, 2011 Author Share Posted April 5, 2011 That's because you are or'ing a string with the mysql_query() returned value. I suspect you meant to use or die(....) on the line after your mysql_query() statement. Went ahead and implemented your suggestion and I end up getting the following error: Error Unknown column 'temp.gid' in 'on clause' Doesn't make much sense to me because even after doing a SELECT * on temp I definitely see the gid column. Quote Link to comment Share on other sites More sharing options...
Farelski Posted April 5, 2011 Author Share Posted April 5, 2011 That's because you are or'ing a string with the mysql_query() returned value. I suspect you meant to use or die(....) on the line after your mysql_query() statement. Went ahead and implemented your suggestion and I end up getting the following error: Error Unknown column 'temp.gid' in 'on clause' Doesn't make much sense to me because even after doing a SELECT * on temp I definitely see the gid column. Figured out the issue, ended up being that the temp table already existed (From a previous function) so I had to drop it in the beginning so everything was failing on the first query. Thanks for helping me PFMaBiSmAd I wouldn't have been able to track down the cause without the die statement =) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.