PHP / Mysql array_pop缺少第一个值 [英] PHP/Mysql array_pop missing first value

查看:70
本文介绍了PHP / Mysql array_pop缺少第一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上会发生什么:

一个人去一个特定的画廊,说GalleryID = 42。我执行查询以获取该图库中的所有图像(GalleryID = 42的值),并执行单独的查询以获取与该图库相关的所有注释(例如GalleryID = 42)。在400张图像中,三张不同的图像上总共可能只有4条评论。

A person goes to a specific gallery, say GalleryID=42. I do a query to grab all of the images in that gallery (with the value of GalleryID=42), and do a separate query to grab all of the comments associated with that gallery (for example GalleryID=42). There may only be 4 comments total on 3 different pictures out of 400 total images.

当我使用do / while循环遍历图像并显示它们时,搜索在循环播放时为每张图片放置的注释数组。如果找到与特定图片匹配的图片ID,则会显示注释值(Comment,CommentAuthor和CommentDate)。

As I loop through the images with a do/while loop, and display them, I search the array of comments that have been placed for each picture as it loops. If it finds the picture ID that matches a specific picture, it displays the comment values (Comment, CommentAuthor, and CommentDate).

这里是图像查询:

SELECT * FROM GalleryData WHERE GalleryID = 42

以及对注释的查询:

SELECT Comment, CommentAuthor, CommentDate, ID FROM Comments WHERE CategoryID=42

然后,我使用以下代码将注释放入可重复使用的查询中:

Then I use this code to put the comments in the reusable query:

while(($Comments[] = mysql_fetch_assoc($rsComments)) || array_pop($Comments));

然后我使用它来遍历数组以查找与特定图片相关的注释

Then I use this to this to loop through the array to find the comments associated with the particular picture

foreach($Comments as $comment) 
{
  if($comment['ID'] == $row_rsGalleries['ID']) 
  {
    echo '<p>'.$comment['Comment'].' - '.$comment['CommentAuthor'].'</p>';
  }
}

问题是,此代码似乎不包括在查询中是第一个注释。

Problem is, that this code seems to not include the very first comment in the query.

现在,这是我做过这样的工作的第一个项目,我不是php / mysql专家,还是新手用户。

Now, this is one of the first projects I have done something like this, and I am not a php/mysql expert, a novice user.

运行查询时,它会显示4个结果,但数组仅包含3个,第一个结果丢失。

When I run the query, it comes up with 4 results, but the array only includes 3, the first result is missing.

推荐答案

对我来说,这种构造非常疯狂。我不明白为什么它会切断第一个要素,但是我真的没有什至倾向于花时间去发现:您需要修正该陈述。在这种情况下使用 || 永远不会给您想要的结果。

This construct looks totally crazy to me. I don't understand why it would cut off the first element, but I don't really feel inclined to even spend the time to find out: You need to fix that statement. Using || in this context is never going to give you the result you want.

您能描述一下这应该做什么吗?

Can you describe what this is supposed to do?

这篇关于PHP / Mysql array_pop缺少第一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆