Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 16th Feb 2010, 07:42 PM   #1
Active Warrior
War Room Member
 
Join Date: 2009
Posts: 70
Thanks: 7
Thanked 9 Times in 7 Posts
Default
php foreach loop horizontal
Share on: 
fb share twitter share gplus share more share

Can anyone point me to some php code that will loop through an xml feed and display the contents horizontally?

I can loop through the feed and have the results displayed vertically but I have no clue how to get them horizontal.

This is how I get the results vertical.
PHP Code:
<?php
foreach($xml->Foods->Food as $Food){
$title = $Food->Title ;
echo 
$title;
?>
This would display the results like

title1
title2
title3

I would like

title1 title2 title3

Thanks!
stitchlips is offline  
Unread 16th Feb 2010, 09:41 PM   #2
Advanced Warrior
War Room Member
 
Bruce Hearder's Avatar
 
Join Date: 2004
Location: Perth, Australia.
Posts: 724
Thanks: 6
Thanked 184 Times in 136 Posts
Default
Re: php foreach loop horizontal
Share on: 
fb share twitter share gplus share more share

The code you have should display them horizontally becuase there is not "break" being issed at the end of each echo statement.

What might be happeining is that the data coming from the xml file contains embedded <br> or <br /> statments.

So try something like this, to see if this fixes the problem:


foreach($xml->Foods->Food as $Food){
$title = str_replace('<br>','',str_replace('<br />','',$Food->Title)) ;
echo $title;


Its not pretty, its only test code..

Hope this helps

Bruce
Bruce Hearder is offline  
Unread 16th Feb 2010, 10:55 PM   #3
PHP Programmer
War Room Member
 
m4rx's Avatar
 
Join Date: 2009
Location: /dev/null
Posts: 138
Thanks: 6
Thanked 12 Times in 12 Posts
Default
Re: php foreach loop horizontal
Share on: 
fb share twitter share gplus share more share

Your code should all display in one line.

If it doesn't you can try something like this.
foreach($xml->Foods->Food as $Food){
$title = $Food->Title ." ";
echo
$title; // Or add it here.
// or just echo this
echo $Food->Title . " ";
}

If you add a space to the end of the title, it should just force it into one line with a space.

--m4rx

We are what we repeatedly do. Excellence, then, is not an act, but a HABIT. ~Aristotle
Bored. Learn everything you need to know about Organic Gardening.
m4rx is offline  
Unread 17th Feb 2010, 04:31 PM   #4
Active Warrior
War Room Member
 
Join Date: 2009
Posts: 70
Thanks: 7
Thanked 9 Times in 7 Posts
Default
Re: php foreach loop horizontal
Share on: 
fb share twitter share gplus share more share

I would like to display it in 3 columns like this and then continue down the page with a total of ten results.




Item1 item2 item3
picture1 picture2 pciture3
price1 price2 price3
link1 link2 link3

like this

Last edited on 17th Feb 2010 at 04:32 PM. Reason: did not dislpay correctly
stitchlips is offline  
Unread 17th Feb 2010, 10:43 PM   #5
Advanced Warrior
War Room Member
 
Bruce Hearder's Avatar
 
Join Date: 2004
Location: Perth, Australia.
Posts: 724
Thanks: 6
Thanked 184 Times in 136 Posts
Default
Re: php foreach loop horizontal
Share on: 
fb share twitter share gplus share more share

I would suggest putting this up as a simple job on RentAcoder and get someone to do the job much faster than waiting for other people here to write your code for you.

I'm sure you get a job like this done for $10 - $50 .. Maybe even a lot less

Give it a try

Bruce
Bruce Hearder is offline  
Closed Thread


Bookmarks

Tags
foreach, horizontal, loop, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 01:13 PM.