Issues with row-switching script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Issues with row-switching script

Post by LiveFree »

Hello,

I have this script, which is displaying the information found from a DB. My goal is to have the script display two records, and then have it create a new row. However, absolutly nothing is being outputted here.

The script:

Code: Select all

 
<?php
        $x = 0;  // Used to determine if we need a new row
        foreach ($query as $data) {
        if ($x == 0) { echo "<tr>"; }
        echo " <td><img src='" . $this->config->site_url_noindex() . "/public/uploads/" . urlencode(str_replace(' ', '_', $data['productImg'])) . "' alt='" . $data['productName'] . "' /><br /><b><a href='" . $this->config->site_url() . "/Gallery/viewProduct/" . $data['productID'] . "/'>" . $data['productName'] . "</a></b></td>";
        if ($x == 2) { echo "</tr>"; }
        $x++;
        if ($x >= 2) {
            $x = 0;
        }
        }
    ?>
 
I cannot see why nothing at all is being outputted, and yes, error_reporting is turned on and nothing is being reported.

Any help would be appriciated.
Cut
Forum Commoner
Posts: 39
Joined: Sat Aug 23, 2008 8:01 pm

Re: Issues with row-switching script

Post by Cut »

I removed the class references and made a random $query array to test it and it worked fine, so I guess the problem lies in one of the things I removed or your server. The code I used to test:

Code: Select all

<table>
<?php
        $query = array('1' => array('productID' => '1111', 'productName' => 'aaa'), '2' => array('productID' => '2222', 'productName' => 'bbb'), '3' => array('productID' => '333', 'productName' => 'ccc'), '4' => array('productID' => '4444', 'productName' => 'dddd'), '5' => array('productID' => '555', 'productName' => 'eeee'));
        $x = 0;  // Used to determine if we need a new row
        foreach ($query as $data) {
        if ($x == 0) { echo "<tr>"; }
        echo " <td><img src=\"\" /><br /><b><a href='" . $data['productID'] . "/'>" . $data['productName'] . "</a></b></td>";
        if ($x == 2) { echo "</tr>"; }
        $x++;
        if ($x >= 2) {
            $x = 0;
        }
        }
    ?>
    </table>
Post Reply