Page 1 of 1

Issues with row-switching script

Posted: Sat Sep 06, 2008 10:52 pm
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.

Re: Issues with row-switching script

Posted: Sun Sep 07, 2008 12:32 am
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>