Added a new code on the page but everything below it crashes. Code that was added: <?php $websites = $data->select ( "Website_Tag" , "*", array ( "TagID" => intval ( $tag_web["TagID"] ) ) ) ; if ( ! empty ( $websites ) ) $counter = 0; foreach ( $websites as $website ) : $web_detail = $data->select ( "Website" , "*" , array ( "WebsiteID" => $website["WebsiteID"] ) ) ; $web_detail = $web_detail[0] ; $counter++; if ($counter > 7) break; ?> <a href="<?php echo base_url.get_sef_url ( $website["WebsiteID"] , "Website" ) ?>/"><?php echo $web_detail["WebsiteName"] ?></a> <?php endforeach ; ?> Code (markup): That is down and crashes: <?php echo $website["WebsiteTitle"] ?> Code (markup): Strange thing is that if I put him down (footer) functions normally.How can I resolve this conflict?
semi-colon isn't needed if it's the last line before the closing php tags ?> Just curious, do you have short_open_tag directive set to 1 or 0 in php.ini ? If it's on 0 then your foreach wouldn't work because you're using the short tag syntax instead of the regular foreach($array as $item){ } syntax.
See, this is why I think the whole foreach : endforeach garbage and the idiocy of opening and closing <?php ?> crap needs to be purged from PHP entirely. This train wreck of openings and closings and good luck EVER lining up any of it is a poster child for that... and why I only ever open <?php and close ?> once per .php file! Likewise, I say the same thing about double quote strings... Of course it should be crashing on the $websites = line, since you're closing more ) than you open... and also illustrates why using too many spaces and not enough carriage returns and tabs makes code harder to read, not easier. AND once I started editing it I found another logic bug -- if there are no websites, your foreach will still try to run... not much point to the IF statement other than nulling the counter. <?php $websites = $data->select( 'Website_Tag','*',array('TagID' => intval($tag_web['TagID']) ); if (!empty($websites)) { $counter = 0; foreach ($websites as $website) { if (++$counter > 7) break; $web_detail = $data->select( 'Website','*', array('WebsiteID' => $website['WebsiteID']) )[0]; echo ' <a href="',base_url.get_sef_url( $website['WebsiteID'],'Website' ),'">',$web_detail['WebsiteName'],'</a>'; } } ?> Code (markup): Much better. That should work just fine. Don't use multiple echo's and exiting out of PHP for not reason when one echo will do the job, don't use that stupid malfing endforeach garbage, if you're going to have a breakout incrementer, do it before you waste time pulling data with a query -- and take the time to use code indentation that actually makes sense. Of course, I don't know what that $data object is, but if it was worth a flying purple fish it probably wouldn't need you to intval that array value, and I suspect that since you're not using all fields it's a waste of RAM and network time to be sending it '*' -- since I'm assuming that's the field list. Also if it was worth using, it would have a way to pass it "LIMIT" so you wouldn't even need that silly $counter variable.