Forum Moderators: coopster
"111"
Its doing each row individually. EXAMPLE
1 row = 1
2 rows = 11
3 rows = 111
4 rows = 1111
and so on... what am i doing wrong,
____________________
here is my code:
$fidcheck = mysql_query("SELECT * FROM phpbb_posts
WHERE forum_id='2'");
while($row = mysql_fetch_array($fidcheck))
{
$pid = $row['post_id'];
$posterid = $row['poster_id'];
$topicid = $row['topic_id'];
$first = mysql_query("SELECT * FROM phpbb_topics
WHERE topic_first_post_id=$pid");
$vidnum = mysql_num_rows($first);
while($row = mysql_fetch_array($first))
{
$pid = $row['topic_first_post_id'];
$posterid = $row['topic_poster'];
$topicid = $row['topic_id'];
$getname = mysql_query("SELECT * FROM phpbb_users
WHERE user_id='$posterid'");
echo $vidnum;
}
}
?>
Seeing as $vidnum comes from -
$first = mysql_query("SELECT * FROM phpbb_topics WHERE topic_first_post_id=$pid");
$vidnum = mysql_num_rows($first);
So your $vidnum of '111' is telling me that there are 111 rows in your php_topics table where topic_first_post_id=$pid.
Is that not what you wanted to do?
<edit>
Oops missed the while loop.
See the much better suggestion below :)
[edited by: PHP_Chimp at 10:39 am (utc) on Nov. 29, 2007]
try this and see if it works
$fidcheck = mysql_query("SELECT pid FROM phpbb_posts WHERE forum_id='2'");
while($row = mysql_fetch_array($fidcheck))
{
$pid = $row['post_id'];
$first = mysql_query("SELECT * FROM phpbb_topics WHERE topic_first_post_id='$pid' ");
$vidnum = mysql_num_rows($first);
echo "for pid=".$pid." we have ".$vidnum." records<br>";
}
my code is..
$fidcheck = mysql_query("SELECT post_id FROM phpbb_posts WHERE forum_id='2'");
while($row = mysql_fetch_array($fidcheck))
{
$pid = $row['post_id'];
$first = mysql_query("SELECT * FROM phpbb_topics WHERE topic_first_post_id='$pid' ");
$vidnum = mysql_num_rows($first);
echo $vidnum;
}
?>
here is my code
$fidcheck = mysql_query("SELECT post_id FROM phpbb_posts WHERE forum_id='2'");
while($row = mysql_fetch_array($fidcheck))
{
$pid = $row['post_id'];
$first = mysql_query("SELECT * FROM phpbb_topics WHERE topic_first_post_id='$pid' ");
$vidnum = mysql_num_rows($first);
$totvidnum = 0;
$totvidnum += $vidnum;
} // end of while loop
echo $totvidnum."<br />\n";
?>
// initialise $totalvidnum [b]before[/b] the while loop
$totalvidnum = 0;
while($row = mysql_fetch_array($fidcheck))
{
$pid = $row['post_id'];
$first = mysql_query("SELECT * FROM phpbb_topics WHERE topic_first_post_id='$pid' ");
$vidnum = mysql_num_rows($first);
// REMOVE $totvidnum = 0;
$totvidnum += $vidnum;
}
echo $totvidnum."<br />\n";
?>