Jump to content

Query is broken


unemployment

Recommended Posts

I get a php error...Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

 

$sql = 	"SELECT
											`pm_messages`.`conversation_id`
										FROM `pm_messages`
										GROUP BY `pm_messages`.`conversation_id`
										WHERE `pm_messages`.`conversation_id` = ${conversation['id']}";

										$result = mysql_query($sql);

										$replies = mysql_fetch_assoc($result);

Link to comment
Share on other sites

For a good tutorial of how to appropriately handle errors & exceptions, check out:

http://www.phpfreaks.com/blog/or-die-must-die

 

Thanks Maq.  I'll start to read this now.  FYI I tried the query below and it fails.

 

$sql = 	"SELECT
		`pm_messages`.`conversation_id` AS `id`
	FROM `pm_messages`
	WHERE `pm_messages`.`conversation_id` = ${conversation['id']}
	GROUP BY `pm_messages`.`conversation_id`
	COUNT `pm_messages`.`conversation_id`";

	$result = mysql_query($sql);

	$replies = mysql_fetch_assoc($result);

	echo $replies['id'];

Link to comment
Share on other sites

Firstly, you have like 3 threads floating around with very similar questions.  Please do not start duplicate topics, it is a huge waste of time.

 

FYI I tried the query below and it fails.

How does it fail?  Did you append the or die() to see what the error was?

Link to comment
Share on other sites

Firstly, you have like 3 threads floating around with very similar questions.  Please do not start duplicate topics, it is a huge waste of time.

 

FYI I tried the query below and it fails.

How does it fail?  Did you append the or die() to see what the error was?

 

Sorry about the multiple threads.  I've tried several variations of this to try and get this working.

 

Error Message: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

Link to comment
Share on other sites

You did not do what I said.  What I said was to change this line to:

$result = mysql_query($sql) or die(mysql_error());

 

The answer, again, is here:

http://www.phpfreaks.com/forums/php-coding-help/total-unique-id%27s-with-php-and-mysql/msg1527874/#msg1527874

 

The order of your clauses are messed up.  Read the manual for the correct order:

http://dev.mysql.com/doc/refman/5.0/en/select.html

 

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.