php foreach loop horizontal

4 replies
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!
#foreach #horizontal #loop #php
  • Profile picture of the author Bruce Hearder
    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
    {{ DiscussionBoard.errors[1761337].message }}
  • Profile picture of the author m4rx
    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
    Signature
    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.
    {{ DiscussionBoard.errors[1761547].message }}
  • Profile picture of the author weaverIT
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[1761804].message }}
    • Profile picture of the author stitchlips
      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
      {{ DiscussionBoard.errors[1764386].message }}
  • Profile picture of the author Bruce Hearder
    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
    {{ DiscussionBoard.errors[1765456].message }}

Trending Topics