我必须显示最近上传的图像,但只有第一个条目继续显示,这是我们最早的图像。我们的数据库是这样构建的:
jos_campaigns_children
campaign_id |child_id | 代码 | 1921年 | 1921年 | GTM-0103-A00627 |
jos_campaigns_children_detail
detail_id |child_year |campaign_id | 5788 | 2013年 | 1920年 | 1921年 | 2011年 | 1921年 | 3656 | 2012年 | 1921年 | 5789 | 2013年 | 1921年 | 1922年 | 2011年 | 1922年 |
源代码上的 HTML 代码:
<img src="/child_images/<?php echo $row_children_list[code]; ?>-<?php echo $row_children_list[child_year]; ?>-S-1.jpg"
当前 HTML 输出:
<img src="/child_images/GTM-0103-A00627-2011-S-1.jpg"
期望输出:
<img src="/child_images/GTM-0103-A00627-2013-S-1.jpg"
我只是不知道用什么语法替换$row_children_list[child_year]
,以便它只显示最近一年。
这是我找到的查询(这是别人的代码,所以我不完全知道我在做什么:)
$query_children_list = "SELECT * FROM `jos_campaigns_children` a, `jos_regions` b, jos_campaigns_children_detail c WHERE (a.published ='1' and a.old_sponsor_id = '' and a.region_id = b.id and a.paypal_profile_status = '0' and a.campaign_id = c.campaign_id)" . $age_query . "" .$gender_query . "" . $location_query . " GROUP BY a.child_id ORDER BY a.campaign_id DESC LIMIT " . $starting_row . ", " . $row_per_page . "";
$result_children_list = mysql_query($query_children_list);
如果您想要一个快速简单的修复,听起来就像您所做的那样,只需更改此
$query_children_list = "SELECT * FROM `jos_campaigns_children` a, `jos_regions` b, jos_campaigns_children_detail c WHERE (a.published ='1' and a.old_sponsor_id = '' and a.region_id = b.id and a.paypal_profile_status = '0' and a.campaign_id = c.campaign_id)" . $age_query . "" .$gender_query . "" . $location_query . " GROUP BY a.child_id ORDER BY a.campaign_id DESC LIMIT " . $starting_row . ", " . $row_per_page . "";
对此
$query_children_list = "SELECT * FROM `jos_campaigns_children` a, `jos_regions` b, jos_campaigns_children_detail c WHERE (a.published ='1' and a.old_sponsor_id = '' and a.region_id = b.id and a.paypal_profile_status = '0' and a.campaign_id = c.campaign_id)" . $age_query . "" .$gender_query . "" . $location_query . " GROUP BY a.child_id ORDER BY c.child_year DESC LIMIT " . $starting_row . ", " . $row_per_page . "";
相关更改是按child_year而不是campaign_id排序。
我看到您在查询中没有使用内部连接。没有它们,很容易获得不可预测的结果。对表 1 使用内部连接,在campaign_id上使用表 2。裁判。