Forum Moderators: open

Message Too Old, No Replies

mysql num rows within another SELECT statement

mysql_num_rows within another SELECT statement

         

danwebster147

11:20 am on Jul 9, 2008 (gmt 0)

10+ Year Member



Morning all,
I hope you can help; I have a problem which is annoying me.
I have a pretty standard SELECT statement which shows rows from MySQL within PHP.
One of the rows is $id - here lies the problem - For each id (or row), I need to take the id and perform a num_rows query within the SELECT statement.
My code is attached.
If anybody has any idea, I'd be hugely grateful!
Thanks in advance.
Dan

$query = "SELECT diary.*, contacts.firstname, lastname FROM diary, contacts

WHERE diary.hostid=contacts.id AND $searchterm = '$search' ORDER BY

'Start'";


$results = mysql_query( $query );

// print out the results
if($results)
{

$number = 1;
while( $diary = mysql_fetch_object( $results ) )
{

// print out the info
$id = $diary -> id;
$venue = $diary -> venue;
$space = $diary -> space;
$start = $diary -> start;
$finish = $diary -> finish;
$details = $diary -> details;
$date = $diary -> date;
$hostid = $diary -> hostid;
$firstname = $diary -> firstname;
$lastname = $diary -> lastname;
$catering = $diary -> catering;
$number = $diary -> number;

echo( "<tr><td><a href='shownotes.php?id=$id'><img

src=\"../images/arrow.png\"></img></a></td><td><a

href='alterdiary.php?id=$id&variable=space&date=$date'>$space</a></td><td><a

href='alterdiary.php?id=$id&variable=start&date=$date'>$start</a></td><td><a

href='alterdiary.php?id=$id&variable=finish&date=$date'>$finish</a></td><td>

<a href=\"alterhost1.php?id=$id&date=$date\">$firstname $lastname</td><td><a

href='alterdiary.php?id=$id&variable=venue&date=$date'>$venue</a></td><td><a

href='alterdiary.php?id=$id&variable=details&date=$date'>$details</a></a></t

d><td><a href='shownotes.php?id=$id'>$id
<?
$norows = mysql_query('SELECT noteid FROM notes WHERE notes.noteid = $id');
$num_rows = mysql_num_rows($norows);
?>
$num_rows $id