Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   php foreach loop horizontal (https://www.warriorforum.com/programming/179948-php-foreach-loop-horizontal.html)

stitchlips 16th February 2010 07:42 PM

php foreach loop horizontal
 
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!

Bruce Hearder 16th February 2010 09:41 PM

Re: php foreach loop horizontal
 
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

m4rx 16th February 2010 10:55 PM

Re: php foreach loop horizontal
 
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

stitchlips 17th February 2010 04:31 PM

Re: php foreach loop horizontal
 
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

Bruce Hearder 17th February 2010 10:43 PM

Re: php foreach loop horizontal
 
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


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