本文介绍了随机php脚本,错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想做的是,按照特定的顺序从mysql数据库中检索数据,这是我的脚本:

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++;
}
}

?>



应该执行以下操作:
来自articleid的回声文章
来自商品编号的回声评论
回声下一个商品编号
来自商品编号的回声评论

现在要解决的问题:

[img] http://i.imgur.com/ADTJE.png [/img]
在数据库上有2条注释,用于articleid 1,它两次显示第二条注释,而忽略了第一条.

商品编号31有1条评论,什么也没有显示.
图片错误.

我似乎无法在代码中找到问题,因此我对任何事情都有帮助.

谢谢



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

推荐答案




这篇关于随机php脚本,错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 22:22