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
https://forums.phpfreaks.com/topic/227782-query-is-broken/
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
https://forums.phpfreaks.com/topic/227782-query-is-broken/#findComment-1174671
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
https://forums.phpfreaks.com/topic/227782-query-is-broken/#findComment-1174674
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
https://forums.phpfreaks.com/topic/227782-query-is-broken/#findComment-1174677
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
https://forums.phpfreaks.com/topic/227782-query-is-broken/#findComment-1174679
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.