Hey
what I am trying to do is, retrieve data from a mysql database in specific order, here's my script:
<?
$aQry = "SELECT * FROM cb_blog_article ORDER BY artid";
$artRes = mysql_query($aQry);
$artNumber = mysql_numrows($artRes);
$i=0;
while ($i < $artNumber) {
$a1 = mysql_result($artRes, $i, "artid");
$a2 = mysql_result($artRes, $i, "name");
$a3 = mysql_result($artRes, $i, "title");
$a4 = mysql_result($artRes, $i, "article");
$a5 = mysql_result($artRes, $i, "date_posted");
echo "<div id = 'test'> $a1. $a2. $a3. $a4. $a5</div>";
$i++;
$cQry = "SELECT * FROM cb_blog_comments WHERE artid = $a1 ORDER BY comid";
$cRes = mysql_query($cQry);
$cNumber = mysql_numrows($cRes);
$j=0;
while ($j < $cNumber) {
$c1 = mysql_result($cRes, $i, "comid");
$c2 = mysql_result($cRes, $i, "username");
$c3 = mysql_result($cRes, $i, "email");
$c4 = mysql_result($cRes, $i, "date_posted");
$c5 = mysql_result($cRes, $i, "comment");
echo "<div id = 'test2'> $c1. $c2. $c3. $c4. $c5 </div>";
$j++;
}
}
?>
It's supposed to do the following:
Echo article from articleid
Echo comment(s) from articleid
Echo next articleid
Echo comment(s) from articleid
Now to the problems:
[img]http://i.imgur.com/ADTJE.png[/img]
There are 2 comments on the db for articleid 1, it displays the 2nd comment twice and leaves out the first.
There is 1 comment for articleid 31, doesn't display anything.
Error in picture.
I can't seem to find the problem in my code, so I am helpful for anything.
Thanks