SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Amend PHP and order XML with XPATH

    Hi all

    I have a XML file holding all my content - a list of hotels which is displayed with PHP as shown below adding a class="last" to every third element, works good.
    My problem now, I need to add another class of class="featured" and extra markup <span>featured</span> to a unique hotel name(s) and maybe sometimes at random.
    The featured class might also be needed on the third element which already has the class="last".

    How do I achieve this with the code below?

    My existing code:
    PHP Code:
    <?php $hotels simplexml_load_file("hotel_listing.xml"); ?>
    <?php $i
    =1; foreach ($hotels->hotel as $hotel): ?>
                  <?php $clss= ($i == 0)? 'class="last"':'' ?>
                  <div <?php echo $clss ?> >
                        <img src="images/<? echo $hotel->img->name ?>">
                        <h3><?php echo $hotel->name ?></h3>
                        <p><?php echo $hotel->description ?></p>
                        <p><b>Rating:</b> <?php echo $hotel->star ?></p>
                </div>
                <? $i++;?>
                <? endforeach ?>
    I would also like to order the hotels using some to sort of xpath.
    I did try the below nothing happened...

    PHP Code:
    <?php $hotels->xpath("star"); ?>
    Any feedback much appreciated

    Barry
    The more you learn.... the more you learn there is more to learn.

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2005
    Posts
    1,675
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it helps... this is the output I already have and the featured output that I'm trying to achieve at the bottom.

    Code HTML4Strict:
    <div>
                        <img src="images/hotel1.jpg">
                        <h3>hotel1</h3>
                        <p>Hotel description....</p>
                        <p><b>Rating:</b> 4</p>
    </div>
    <div>
                        <img src="images/hotel2.jpg">
                        <h3>hotel2</h3>
                        <p>Hotel description....</p>
                        <p><b>Rating:</b> 3</p>
    </div>
    <div class="last">
                        <img src="images/hotel3.jpg">
                        <h3>hotel3</h3>
                        <p>Hotel description....</p>
                        <p><b>Rating:</b> 4</p>
    </div>

    The featured markup and class I'm trying to add.

    Code HTML4Strict:
    <div class="featured">
                       <span>featured</span> 
    		<img src="images/hotel4.jpg">
                        <h3>hotel4</h3>
                        <p>Hotel description....</p>
                        <p><b>Rating:</b> 4</p>
    </div>

    Thanks
    The more you learn.... the more you learn there is more to learn.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •