2010-03-22 3 views
-1

мне нужна помощь с массивом и петлей Еогеаспа,PHP массив и Еогеасп помощь

У меня есть массив, который возвращаемые данные из базы данных, в основном это список названий и изображений, связанных с ним, его выглядит немного как это,

Array 
(
    [0] => Array 
     (
      [contentImageId] => 28 
      [contentImageName] => yellow.png 
      [contentImageType] => .png 
      [contentImagePath] => /var/www/bangmarketing.bang/media/uploads/contentImages/7/yellow.png 
      [isHeadlineImage] => 1 
      [contentImageDateUploaded] => 1265388055 
      [contentId] => 7 
      [dashboardUserId] => 0 
      [contentTitle] => Another Blog 
      [contentAbstract] => <p>This is another blog and it is shit becuase this does not work</p> 
      [contentBody] => <p>ioasfihfududfhdufhuishdfiudshfiudhsfiuhdsiufhusdhfuids</p> 
      [contentOnline] => 1 
      [contentAllowComments] => 0 
      [contentDateCreated] => 1265388034 
      [categoryId] => 1 
      [categoryTitle] => blogsss 
      [categoryAbstract] => <p>asdsdsadasdsadfdsgdgdsgdsgssssssssssss</p> 
      [categorySlug] => blog 
      [categoryIsSpecial] => 0 
      [categoryOnline] => 1 
      [categoryDateCreated] => 1266588327 
     ) 

    [1] => Array 
     (
      [contentImageId] => 31 
      [contentImageName] => sophie.jpg 
      [contentImageType] => .jpg 
      [contentImagePath] => /var/www/bangmarketing.bang/media/uploads/contentImages/9/sophie.jpg 
      [isHeadlineImage] => 1 
      [contentImageDateUploaded] => 1265713423 
      [contentId] => 9 
      [dashboardUserId] => 0 
      [contentTitle] => Bang appoints a new Senior Designer 
      [contentAbstract] => <p>Bang has appointed a new Senior Designer in the wake of a number of major client wins.</p> 
      [contentBody] => <p>After recently signing up clients including the National Trust and Propaganda, Bang has hired Sophie Smith to join its creative team.</p> 

<p>Sophie brings over twelve years of extensive design experience in Bang's core market sectors, including social housing and public sector brands.</p> 
<p>Sophie has significant experience of branding and strategic design projects for a broad range of clients, including HBoS, Harvey's, TKMaxx and Places for People.</p> 
<p>Warren Watts Creative Director at Bang commented; "Sophie has already proven an invaluable addition to our growing studio. In only her second week, she helped produce the creative that led to the National Trust account win".</p> 
      [contentOnline] => 1 
      [contentAllowComments] => 0 
      [contentDateCreated] => 1265713155 
      [categoryId] => 8 
      [categoryTitle] => News 
      [categoryAbstract] => <p>The world at Bang Marketing moves fast, keep up to date w 
      [categorySlug] => news 
      [categoryIsSpecial] => 0 
      [categoryOnline] => 1 
      [categoryDateCreated] => 1265283717 
     ) 

    [2] => Array 
     (
      [contentImageId] => 32 
      [contentImageName] => selectadna.jpg 
      [contentImageType] => .jpg 
      [contentImagePath] => /var/www/bangmarketing.bang/media/uploads/contentImages/10/selectadna.jpg 
      [isHeadlineImage] => 1 
      [contentImageDateUploaded] => 1265713937 
      [contentId] => 10 
      [dashboardUserId] => 0 
      [contentTitle] => Bang client experiences growth 
      [contentAbstract] => <p>Selectamark, the UK's leading asset protection specialist recorded its best figures for five years in 2008.</p> 
      [contentBody] => <p>The results were released during an extremely challenging economic climate, and just over 12 months into the organisation's relationship with Bang.</p> 
<p>Bang has been working on developing Selectamark's range of product brands, which include the UK's leading asset tracking and labelling system Selectamark, and second generation forensic marking system, SelectaDNA. Despite gloomy national economic forecasts, Selectamark has enjoyed an extremely successful start to 2009 &ndash; picking up several major new clients in February, and with discussions taking place to expand operations beyond the UK and Netherlands to Germany and New Zealand.</p> 

<p>Chris Garratt, Marketing Director at Bang Marketing Ltd explained "Selectamark adopted a well planned, coordinated and consistent strategy in 2008, and the results speak for themselves.</p> 
<p>"Due to the success last year and the forecasts for increased levels of acquisitive crime we're hoping Selectamark's key products will enjoy similar growth in 2009".</p> 
<p>Selectamark Security Systems provides DNA Forensic Marking products (SelectaDNA) and Visible Marking solutions (Selectamark and Logomark) to prevent burglaries, theft from void properties, theft of boilers, and theft of valuable metals such as lead from roofs. Selectamark have supplied these Secured By Design crime prevention products to Police, local authorities and housing associations for 25 years.</p> 
<p>The Selectamark system has now marked over 25 million items, and is patented and distributed world-wide. Visit www.selectadna.co.uk for product details.</p> 
<p>James Brown, Sales Director at Selectamark said "We have been absolutely delighted with the work Bang has done for us. In a short space of time, the Bang team has created a wide range of extremely fresh and professional-looking sales and marketing material for us to use, as well as devising a detailed marketing strategy which has now been implemented. We would have no hesitation in recommending Bang to other organisations."</p> 
      [contentOnline] => 1 
      [contentAllowComments] => 0 
      [contentDateCreated] => 1265713888 
      [categoryId] => 8 
      [categoryTitle] => News 
      [categoryAbstract] => <p>The world at Bang Marketing moves fast, keep up to date w 
      [categorySlug] => news 
      [categoryIsSpecial] => 0 
      [categoryOnline] => 1 
      [categoryDateCreated] => 1265283717 
     ) 
) 

Как вы можете видеть contentTitle изменения, каждый раз, но когда-то это возвращает тот же заголовок контента, я искал способ, чтобы добавить разрыв между возвращаемых данных, если содержание Title изменения ценности?

Возможно ли это? и как? Я действительно борется здесь.

Благодаря

+0

Что вы подразумеваете под разделом? – Kevin

+0

@kevin Я думаю, что hes говорит о том, когда hes выдает html во время цикла через массив ... он хочет добавить как hr или что-то, когда заголовок изменяется. – prodigitalson

ответ

2

Как перебрать, вы можете иметь временную переменную для хранения последнего отображения названия

$lastTitle=''; 
foreach ($array as $record) 
{ 
    if ($lastTitle != $record['contentTitle']) 
    echo '<hr>'; 

    $lastTitle = $record['contentTitle'); 

    // display content from record 

} 
1

Если я вас правильно понял, вы хотите отобразить делитель каждый раз, когда contentTitle является отличное от значения, которое оно имело в последней итерации.
Вы создаете галерею здесь, не так ли? Если это так, я бы сказал следующее:

$lastTitle = ''; 
foreach($yourArray as $value) 
{ 
    if(!$lastTitle || $lastTitle != $value['contentTitle']) 
    { 
     echo '<h2>' . $value['contentTitle'] . '</h2><hr />'; // Display divider 
     // Do some other stuff 
    } 

    $lastTitle = $value['contentTitle']; 
    // Display image or whatever you want to do 
}