Jump to content

Select top row of MySQL query


rfighter

Recommended Posts

I'm still not completely sure what you mean. But maybe your looking for 'LIMIT'

 

<?php
$newq = mysql_query("SELECT * FROM threadread WHERE userid = '$logged[id]' AND threadid =    '$threadid' ORDER BY readtime DESC LIMIT 10");

 

I would use that, and that is what I mean, but I also need to do a num_rows, to check if there are no results, and using a num_rows with a LIMIT returns a T_Variable error, so is there any other way please?

post the code where you're trying to do num_rows because the query string is valid (except for the fact that you said you want just 1, not 10, so it would be "...desc limit 1")

 

		$newq = mysql_query("SELECT * FROM threadread WHERE userid = '$logged[id]' AND threadid = 	'$threadid' ORDER BY readtime DESC LIMIT 0,1");

	$numrows = mysql_num_rows($newq);

	$newarray = $mysql_fetch_array($newq);

 

The error now is: Fatal error: Call to undefined function: () in /home/xxx/public_html/newposts.php on line 44

 

 

Line 44 is "$newarray = $mysql_fetch_array...."

 

EDIT: I realise what's wrong. I put a $ in front of mysql_fetch_array

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.