Jump to content

[SOLVED] Help finding how many values found in an array.


gergy008

Recommended Posts

Ok. I'm making a function that returns a string (Which gets echoed by the line that calls it).

 

I want the string to say how many messages a user has. Now I have this up to now, But I have no idea how to get it to work. I need the $results2 variable to say the amount of messages the SQL query found.

 

How do I go abouts this?

 

Thanks in advance!

 

	$sql="SELECT cash FROM message WHERE login='".$_SESSION["login"]."' and read='false'";
	// OREDER BY id DESC is order result by descending
	$results = mysql_query($sql);
	$arr = mysql_fetch_row($results);
	$results2 = $arr[0];
	return"<FONT COLOR='3366CC'> $results2 </FONT> new messages!";

After a long wait... I got

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/vhosts/www.gergy.info/functions.php on line 482

 

for this function:

 

function getmsg(){
if(isset($_SESSION["loggedIn"])){
	global $link;

	$sql="SELECT * FROM message WHERE to='".$_SESSION["login"]."' and read='false'";
	// OREDER BY id DESC is order result by descending
	$results = mysql_query($sql);
	$results2 = mysql_num_rows($results);
	return"<FONT COLOR='3366CC'> $results2 </FONT> new messages!";
}
}

That's means your query is failing, and your not performing any error handling to handle it.

 

Ah yes... I forgot. It says I have incorrect syntax? But I see no incorrect syntax here:

 

"  SELECT * FROM message WHERE to=' ".$_SESSION["login"]." ' AND read='0'  "

 

Read is a bool value by the way. I added spaces after and before the quotes to make it neater to read.

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.