Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:01:20+00:00 2026-06-04T02:01:20+00:00

I have here a quite complicated loop what I would like to modify while

  • 0

I have here a quite complicated loop what I would like to modify while is not really working as I expected. The problem is: my if statements else condition is generating trash and I don’t really know where the problem comes

enter image description here

<div id="container">
    <?php include 'header.php';
    foreach ($vars as $item):



    if (is_array($item['productItems'])):?>

    <div class="product_box">
        <h4>
            <?php echo $item['title']?>
        </h4>

        <?php foreach($item['productItems'] as $products):?>

        <?php foreach($products as $key=>$product):?>


        <div class="product">

            <div class="image_holder">

                <a href="<?php echo $product['image']['medium'];?>" class="preview">
                    <img src="<?php echo $product['image']['small'];?>"
                    alt="gallery thumbnail" title="" />
                </a>


                <?php foreach($product['trackingLinks'] as $key=>$trackinglink): ?>
                <a href="<?php echo $trackinglink[0]['ppc']?>"> <span><?php echo $product['name'];?>
                </span>
                </a>
            </div>

            <h5>
                <?php echo 'Preise:&nbsp;'. $product['price'].' &nbsp;'.$product['currency'];?>
            </h5>
            <span><?php echo 'Versand Kosten:&nbsp;'.$product['shippingCosts'].'&nbsp;EUR';?>
            </span>
            <p>
                <?php echo (substr($product['descriptionLong'], 0,150 )).'<a href="'.$trackinglink[0]['ppc'].'">...mehr</a>';?>
            </p>
            <a class="shopping_button"
                href="<?php echo $trackinglink[0]['ppc']?>">zum Shop</a>



        </div>
<?php endforeach ?>
        <?php endforeach ?>
                <?php endforeach ?>

        <div class="ajax_bar">

            <select id="ajax_call" size="1" name="Weitere Produkte">
                <option value='50'>Weitere Produkte</option>
                <option value='100'>weitere 100</option>
                <option value='150'>weitere 150</option>
            </select>

        </div>

    </div>

    <?php else: ?>


    <div class="text_box">
        <h2>
            <?php echo $item['title'];?>
        </h2>
        <p>
            <?php echo $item['text'];?>
        </p>


    </div>
        <?php endif; ?>
            <?php endforeach; ?>


<?php include 'footer.php';?>

</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:01:22+00:00Added an answer on June 4, 2026 at 2:01 am

    I’m going to make a wild guess here and say that this is because you don’t escape your output using htmlspecialchars or htmlentities.

    If you’re not sure what’s inside the for-loop, use this nifty construct to debug on page:

    echo '<pre>', htmlspecialchars(print_r($vars, true)), '</pre>';
    

    It also helps to look at the page source instead; this usually gives vital clues as to why your page layout is so messed up.

    Update

    Okay got it! It’s because of this:

    <?php else: ?>
    <div class="text_box">
        <h2>
            <?php echo $item['title'];?>
        </h2>
        <p>
            <?php echo $item['text'];?>
        </p>
    

    The $item is a string here, and $item['title'] is understood by PHP as $item[0] which is the first character of $item 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quite a simple problem here and not sure why it's being so complicated. Have
I'm quite new here. I have a problem with the new iOS 5.1 slide-in
I have read quite a few selcet+update questions in here but cannot understand how
This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I hope I will find a help here. I have a quite complex MVC
I have just been helped on a problem I have here . var win
For my first question here I would like to ask you how you'd do
I'm not really pro and find my question quite hard to describe, so please
I'm not quite sure how to phrase this, so bear with me. I have
My code that I have is quite large and complicated so I won't waste

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.