Jump to content

Recommended Posts

I have this PHP code, it creates 1 row of the 3 latest new items in our shopping cart:

 

<tr align="center" valign="top">
<?php
//Specify the query
$query = 'SELECT * FROM `tbl_item` where category_id not in (104,105,106,107,108,109,110,111,112,113,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,132,133,138,139,140) GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3';
//Execut the query
$result = mysql_query($query)
       or die ("Error. Unable to perform query.");

//Loop through all the results, displaying each one
while ($row = mysql_fetch_array($result))
  {
     extract($row);
       $item_name = str_replace(" ", "_",$item_name);
echo "<td width=\"33%\" bgcolor=\"#c2edaa\" style=\"border: 1px solid rgb(45, 135, 7);\">\n";
echo "<a href=\"$URL/item/$item_name/$item_id\"><img src=\"$SSL_URL/item_images/$thumbnail_image\" width=\"110\" height=\"100\" alt=\"$short_description\" border=\"0\" /></a><br />\n";
echo "<b>$row[item_name]</b><br />\n";
echo "$row[short_description]";
echo "</td>\n";
}
?></tr>

 

But now I'd like to display 9 items, so 3 rows of 3 items per row... I don't know how to include the <tr> tag into the php to make it loop per each 3 items, does anyone have an idea how to do this?

 

Thanks ;)

Thank you, CV. I don't need to include the table start and end, because I have it as you'll see below, and also, this is how I included your code, I tried other ways, but keep getting an error.

 

The error is: Parse error: syntax error, unexpected $end in /home/domain/public_html/template/hctheme/index.php on line 76

 

My code:

 

<table class="newitems" cellspacing="1" cellpadding="0" border="0" bgcolor="#ffffff" align="center" width="100%" style="border: 1px solid rgb(45, 135, 7);">
<tr><td colspan="3" align="center"><strong>New Products</strong></td></tr>
<?php
//Specify the query
$query = 'SELECT * FROM `tbl_item` where category_id not in (104,105,106,107,108,109,110,111,112,113,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,132,133,138,139,140) GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3';
//Execut the query
$result = mysql_query($query)
       or die ("Error. Unable to perform query.");

//Loop through all the results, displaying each one
while ($row = mysql_fetch_array($result))
   $cols = 0;
   while ($cols < 20) {
      echo ($cols % 3 == 0)? "</tr><tr>" : "";
{
extract($row);
$item_name = str_replace(" ", "_",$item_name);
echo "<td width=\"33%\" bgcolor=\"#c2edaa\" style=\"border: 1px solid rgb(45, 135, 7);\">\n";
echo "<a href=\"$URL/item/$item_name/$item_id\"><img src=\"$SSL_URL/item_images/$thumbnail_image\" width=\"110\" height=\"100\" alt=\"$short_description\" border=\"0\" /></a><br />\n";
echo "<b>$row[item_name]</b><br />\n";
echo "$row[short_description]";
echo "</td>\n";
$cols++;
}
?></table>

 

I'm not quite sure how to adapt your code into mine.  ???

Ah see well the while loop in my code was just an example loop. You would use your $row = ... instead of that.  Also you need to move $cols = 0; out of the loop:

 

<table class="newitems" cellspacing="1" cellpadding="0" border="0" bgcolor="#ffffff" align="center" width="100%" style="border: 1px solid rgb(45, 135, 7);">
<tr><td colspan="3" align="center"><strong>New Products</strong></td></tr>
<?php
//Specify the query
   $query = 'SELECT * FROM `tbl_item` where category_id not in (104,105,106,107,108,109,110,111,112,113,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,132,133,138,139,140) GROUP BY `item_id` ORDER BY `item_id` DESC LIMIT 3';
//Execut the query
   $result = mysql_query($query)
       or die ("Error. Unable to perform query.");

//Loop through all the results, displaying each one
   $cols = 0;
while ($row = mysql_fetch_array($result)) {

   echo ($cols % 3 == 0)? "</tr><tr>" : "";
   extract($row);
   $item_name = str_replace(" ", "_",$item_name);
   echo "<td width=\"33%\" bgcolor=\"#c2edaa\" style=\"border: 1px solid rgb(45, 135, 7);\">\n";
   echo "<a href=\"$URL/item/$item_name/$item_id\"><img src=\"$SSL_URL/item_images/$thumbnail_image\" width=\"110\" height=\"100\" alt=\"$short_description\" border=\"0\" /></a><br />\n";
   echo "<b>$row[item_name]</b><br />\n";
   echo "$row[short_description]";
   echo "</td>\n";
$cols++;
}
?></table>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.