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...
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.
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: [isdoo] foreach query
By ross - June 18, 2009
Hi there.
Thanks for posting!
Would something like this work:
Latest <?php echo $news1Record['league'] ?> News
It would just output whatever you have in that field. The only thing is that you would probably want to do a quick search and replace for the "_" to turn them into space:
Thanks for posting!
Would something like this work:
Latest <?php echo $news1Record['league'] ?> News
It would just output whatever you have in that field. The only thing is that you would probably want to do a quick search and replace for the "_" to turn them into space:
Latest <?php echo str_replace("_", " ", $news1Record['league']); ?> News
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/