Jump to content

Can I split showing of content of dynamic list in 2 parts , when I echo list


nia_st210

Recommended Posts

Hi , I have one question .. Can I split showing of content of dynamic list in 2 parts , when I echo list in code ..

 

<?php 
// Run a select query to get my letest 8 items
// Connect to the MySQL database  
include "../connect_to_mysql.php"; 
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
		 $product_name = $row["product_name"];
		 $price = $row["price"];
		 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
		 $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2">
        <tr>
          <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td>
          <td width="83%" valign="top">' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product Details</a></td>
        </tr>
      </table>';
    }
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

 

 

 

<p><?php echo $dynamicList; ?><br />
</p>

 

It works ok, and putting my files, everything works, but when I put 8 pictures with price and other details, it just show one image with details and another image below with details, and the third image below and so on ..

Can I split dynamic list to show 4 images with details on the left side and 4 on the right side?

 

Thank you in advance for help , if is possible :)

Ya you can, Try this. I haven't tested but I think it will get you what you are looking for.

 

<?php
$i = 0;
while($row = mysql_fetch_array($sql)){ 
             $tr = ($i % 2) ? '<tr>' : '';
             $trclose = ($i % 2) ? '</tr>' : '';
             $id = $row["id"];
		 $product_name = $row["product_name"];
		 $price = $row["price"];
		 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
		 $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2">
        '.$tr.'
          <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td>
          <td width="83%" valign="top">' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product Details</a></td>
        '.$trclose.'
      </table>'.
	$i++;
    }
?>

Hey, thanks for posting your code , but when I put it in my , it is not spliting on 2 parts , only showing below image and product detail numbers,after first picture i uploaded as admin , below is 0 , after second below is 1 , and so on until 8th picture where of course below is number 7 ..

 

I'm making website for selling my books , so I wanted when people go on part of website where are picture of books and for sale details (dynamic_list) ,

that they dont see like 40 pictures and details one below another .. I wanted them to see it in 2 columns .. I wanted to do that in php , and I made shopping card and everything works exept it is showing books one below another .. Not nice for viewing when I have 40 books for sale .. 

 

 

<?php 
// Run a select query to get my letest 8 items
// Connect to the MySQL database  
include "storescripts/connect_to_mysql.php"; 
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
$i = 0;
while($row = mysql_fetch_array($sql)){ 
             $tr = ($i % 2) ? '<tr>' : '';
             $trclose = ($i % 2) ? '</tr>' : '';
		 $id = $row["id"];
		 $product_name = $row["product_name"];
		 $price = $row["price"];
		 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
		$dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2">
        '.$tr.'
          <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 
	  1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td>
          <td width="83%" valign="top">' . $product_name . '<br />
            $' . $price . '<br />
            <a href="product.php?id=' . $id . '">View Product Details</a></td>
        '.$trclose.'
      </table>'.
	$i++;
    }
} else {
$dynamicList = "We have no products listed in our store yet";
}
mysql_close();
?>

 

I'm sure we can get this to work for you but I am having a really hard time picturing what you are describing. Can you provide a link or a screen shot of what you have and one of what you are trying to accomplish? I thought I understood but I must have had it wrong.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.