Jump to content


Photo

Alternating Items


  • Please log in to reply
2 replies to this topic

#1 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 20 March 2006 - 04:11 PM

I'm sure this one is easy for someone with more experience to figure out, but after spending over 2 hours of looking at errors I'm stumped...

I'm trying to create a page where you view items, and have 3 rows, with 3 items per row, a total of 9 images per page. I was able to get the 3 rows to work, but can't seem to get the 3 items per row to take shape. Can somebody look at my code and tell me what I have to do?

<?php

if(isset($_GET['category']));
  switch($_GET['category'])
 {
    case 'bracelets':
    $pTitle = 'Bracelets';
    break;
 
    case 'cufflinks':
    $pTitle = 'Cufflinks';
    break;

    case 'nameplates':
    $pTitle = 'Nameplates';
    break;
     
    case 'pendants':
    $pTitle = 'Pendants';
    break;

    case 'Earrings':
    $pTitle = 'Our Earring Collection';
    break;
     
    case 'moneyclips':
    $pTitle = 'Money Clips';
    break;
  }  
    
include ('include/header.php');

?>

<table>
    <tr>
        <td class="shadowL"><img src="images/spacer.gif" width="19" height="1" /></td>
        <td>
            <table>
                <tr>
                    <td class="lftNavHldr"><?php include ('include/leftNav.php'); ?></td>
                    
                    <td class="mainHldr">
                        <table>
                            <tr><td class="pTitle"><? echo $pTitle; ?></td></tr>
                        </table>

                        <?php

                            require_once ('include/mysql_connect.php');
                            
                            if(!$_GET['page']) {
                                $_GET['page'] =1;
                                }

                            $offset = ($_GET['page']-1)*3;

                            $query = "SELECT count(*) as thecount from products where category = '{$_GET['category']}' and status = 'Active'";
                            $result = mysql_query($query); 
                            $row = mysql_fetch_array($result);
                            $total = $row[thecount];
            
                            $pages = ceil($total/3);
                        
                            $query = "SELECT * FROM products where category = '{$_GET['category']}' and status = 'Active' limit $offset,3";
                            $result = mysql_query($query); 
                            $numrows = mysql_num_rows($result); 
                            while($row = mysql_fetch_array($result)){ 
                            
                            $image = "<img src=\"products/{$row[Category]}/{$row['SKU']}s.jpg\" width=\"155\" height=\"155\" alt=\"$alt\"/>";
                            
                        echo "                        
                        <div align=\"center\">
                        <table>
                            <tr>
                                <td class=\"itmHldr\">
                                    <table width=\"100%\">
                                        <tr><td class=\"imgHldrS\"><a href=\"view_item.php?SKU={$row['SKU']}\">$image</a></td></tr>
                                        <tr><td class=\"itmDescS\">{$row['Desc_S']}</td></tr>
                                    </table>
                                    <div align=\"center\">
                                    <table>
                                        <tr>
                                            <td class=\"prc1S\">M.S.R.P</td>
                                            <td class=\"prc2S\">$ {$row['MSRP']}</td>
                                        </tr>
                                        <tr>
                                            <td class=\"prc3S\">Your Price</td>
                                            <td class=\"prc4S\">$ {$row['Sell']}</td>
                                        </tr>
                                        <tr>
                                            <td class=\"prc5S\">You Save</td>
                                            <td class=\"prc6S\">$1245.00</td>
                                        </tr>
                                    </table>
                                    </div>
                                </td>
                                
                                <td><img src=\"images/spacer.gif\" width=\"20\" height=\"1\" /></td>
                                
                                <td class=\"itmHldr\">
                                    <table width=\"100%\">
                                        <tr><td class=\"imgHldrS\"><a href=\"view_item.php?SKU={$row['SKU']}\">$image</a></td></tr>
                                        <tr><td class=\"itmDescS\">{$row['Desc_S']}</td></tr>
                                    </table>
                                    <div align=\"center\">
                                    <table>
                                        <tr>
                                            <td class=\"prc1S\">M.S.R.P</td>
                                            <td class=\"prc2S\">$ {$row['MSRP']}</td>
                                        </tr>
                                        <tr>
                                            <td class=\"prc3S\">Your Price</td>
                                            <td class=\"prc4S\">$ {$row['Sell']}</td>
                                        </tr>
                                        <tr>
                                            <td class=\"prc5S\">You Save</td>
                                            <td class=\"prc6S\">$1245.00</td>
                                        </tr>
                                    </table>
                                    </div>
                                </td>
                                
                                <td><img src=\"images/spacer.gif\" width=\"20\" height=\"1\" /></td>
                                
                                <td class=\"itmHldr\">
                                    <table width=\"100%\">
                                        <tr><td class=\"imgHldrS\"><a href=\"view_item.php?SKU={$row['SKU']}\">$image</a></td></tr>
                                        <tr><td class=\"itmDescS\">{$row['Desc_S']}</td></tr>
                                    </table>
                                    <div align=\"center\">
                                    <table>
                                        <tr>
                                            <td class=\"prc1S\">M.S.R.P</td>
                                            <td class=\"prc2S\">$ {$row['MSRP']}</td>
                                        </tr>
                                        <tr>
                                            <td class=\"prc3S\">Your Price</td>
                                            <td class=\"prc4S\">$ {$row['Sell']}</td>
                                        </tr>
                                        <tr>
                                            <td class=\"prc5S\">You Save</td>
                                            <td class=\"prc6S\">$1245.00</td>
                                        </tr>
                                    </table>
                                    </div>
                                </td>
                            </tr>
                        </table><br />\n";
                            $row_count++; 
                            } // End of record loop.
    
                            mysql_close($dbc);
                        ?>    
                        </div>
                                                
                        <table width="100%">
                            <tr>
                                <td class="pgNums">
                            <?
for($x = 1; $x<= $pages; $x++) {

if($_GET['page'] != $x) {
  echo "<a href=\"view_items.php?category={$_GET[category]}&page={$x}\">{$x}</a>
";
}
else {
  echo "[{$x}] ";
}

}
                            ?>
                                </td>
                            </tr>
                        </table>        
                            
                    </td>
                </tr>
            </table>
        </td>
        <td class="shadowR"><img src="images/spacer.gif" width="19" height="1" /></td>
    </tr>
</table>
<?php include ('include/footer.php'); ?>

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 20 March 2006 - 05:59 PM

To use your current method, you would have to call $row = mysql_fetch_array($result) between every < td >. To do it correctly, you need to have a column count, and your containing row would be closed when your column count == 3. That way, you call your main chunk of code that holds the item only once within the loop.

I don't know if that makes sense, but it's hard for me to tell what it's currently doing.

Info: PHP Manual


#3 DBookatay

DBookatay
  • Members
  • PipPipPip
  • Advanced Member
  • 334 posts
  • LocationCT

Posted 21 March 2006 - 01:42 AM

[!--quoteo(post=356686:date=Mar 20 2006, 12:59 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Mar 20 2006, 12:59 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I don't know if that makes sense, but it's hard for me to tell what it's currently doing.
[/quote]

You're right, that makes NO sense to me... Could you possible show me a working example?
I would apprechiate it...

$result mysql_query("SELECT finger FROM hand WHERE id=3"); 
echo 
$result





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users