Jump to content

Queries failing in PHP runing successfully in PHPMyadmin


Farelski

Recommended Posts

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 =)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.