Jump to content

Num_rows problem


mike12255

Recommended Posts

Hey guys I cant seem to find this error guess ive been looking at this screen to long to try and get this project done in time would appriciate if someone could take a fresh look at it and tell me where I went wrong. Basically im trying to get the number of entries returned by my query. I echoed out the query and manually entered it into phpmyadmin there is a 1 row result however whenever i kill $num_result it doesnt give me any  output.

<?php

public function getNewMessages()
{
	global $db,$db_table_prefix;

	$sql = "SELECT
			*
			FROM
			messages
			WHERE
			`to_id` = '".$db->sql_escape($this->user_id)."' AND `read` = 0";




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

	$num_rows = mysql_num_rows($res);

	die ($num_rows); // does not return a value



	return $num_rows;

}


?>

Link to comment
Share on other sites

From the manual page of exit(), for which die() is an alias:

 

If status is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.

 

In other words, use something other than die() to print out the number of rows.

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.