2014-04-08 4 views
2

업로드 된 최근 이미지를 표시해야하지만 첫 번째 항목 만 표시되는 것이 가장 오래된 이미지입니다. 우리의 데이터베이스는 다음과 같이 내장되어 있습니다 :PHP 테이블에서 최신 연도 표시

jos_campaigns_children

 
campaign_id | child_id |  code  | 
    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); 
+0

귀하의 검색어는 어디입니까? –

+0

어떻게'$ row_children_list []'를 만들 수 있습니까? – paqogomez

+0

쿼리보기가없는'where child_year = max (child_year)'를 제안 할 수 있습니다. –

답변

0

난 당신이 내부가 쿼리에 조인 사용하지 않는 볼 수 있습니다. 그것들이 없으면 예기치 않은 결과를 얻는 것이 쉽습니다. campaign_id의 표 1 및 표 2에서 내부 조인을 사용합니다. 당신이 당신이 할 같은 소리 빠르고 쉬운 수정을 원하는 경우 Ref.

1

, 그냥이

$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 . ""; 

관련 변화가 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 c.child_year DESC LIMIT " . $starting_row . ", " . $row_per_page . ""; 

로 변경 campaign_id.

+0

오, 그게 효과가있는 것처럼 보였지만 아이의 목록이있는 순서를 뒤집습니다. 이미지는 동일하게 유지됩니다. 그래도 고마워! 나는 그 효과가 어떻게 작용하는지 조금 더 가르쳐 주었다고 생각합니다. – Tony

+0

코드를 이메일로 보내 주시면 도와 드리겠습니다. –

관련 문제