foreach query

3 posts by 2 authors in: Forums > CMS Builder
Last Post: June 20, 2009   (RSS)

By isdoo - June 17, 2009

Hi all,

Can some kind person point me in the right direction.

I have some php code...

<?php if ($news1Record['league'] == 'Premier_League'){
echo "<h3>Premier League News</h3>";
}
elseif ($news1Record['league'] == 'United_Counties_Premier'){
echo "<h3>United Counties League News</h3>";
}
elseif ($news1Record['league'] == 'Wessex_Premier'){
echo "<h3>Wessex League News</h3>";
}
elseif ($news1Record['league'] == 'Western_Premier'){
echo "<h3>Western League News</h3>";
}
else{
echo "<h3>Latest News</h3>";
}
?>


Which currently goes on for some 20 odd times.

As I wish to do something similar with clubs, I do not really wish to input 1800 odd lines of code, so would like to use a foreach query to compose the code so that I can pull in various includes of external scripts (as well as the wording above, which is stored in 'leagues' database and 'league_name' table and 'leagues' database 'league_known' table.

So say....

elseif ($news1Record['league'] == 'Western_Premier'){
echo "<h3>Western League News</h3>";

is

elseif ($news1Record['league'] == '$record['league_name']'){
echo "<h3>$record['league_known'] News</h3>";

Can some kind person point me in the right direction as to how the code is written for CMS builder so that it will go to the database and pull in the information.

If I can get the above one working in code, then hopefully I can figure out the more complicated version.

If not, I will ask for a price to code it for me (but as I do not earn from the site, would like to try and do it myself if poss).

Assuming that it is even possible.

Thanks.

Re: [ross] foreach query

By isdoo - June 20, 2009

Thanks Ross - appreciated.