DynamicList in three columns

i want to display my sql database products in three columns …
any help is highly appreciated…

[php]<?php

error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
?>

<?php // Run a select query to get my letest 6 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 0,4"); $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 .= '
' . $product_name . ' ' . $product_name . '
$' . $price . '
View Product Details
'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> <?php // Run a select query to get Next 6 items // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicList1 = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC limit 5,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"])); $dynamicList1 .= '
' . $product_name . ' ' . $product_name . '
$' . $price . '
View Product Details
'; } } else { $dynamicList1 = "We have no products listed in our store yet"; } mysql_close(); ?> <?php // Run a select query to get my Next 6 items in the third column. // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $dynamicList2 = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 9,12"); $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"])); $dynamicList2 .= '
' . $product_name . ' ' . $product_name . '
$' . $price . '
View Product Details
'; } } else { $dynamicList2 = "We have no products listed in our store yet"; } mysql_close(); ?>[/php]

[code]

Store Home Page
<?php include_once("template_header.php");?>

Health Category

<?php echo $dynamicList; ?>

 

<?php echo $dynamicList1; ?>


 

<?php echo $dynamicList2; ?>

<?php include_once("template_footer.php");?>
[/code]

You’re wasting a ton of code. The code in the 2nd post http://www.webdeveloper.com/forum/showthread.php?172344-php-and-html-table what you want. Since you apparently just want 4 cells across, change the 6 to 4.

I don’t know if this will work, as i don’t have any way of testing it yet, but give this a try
[php]<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);

include “storescripts/connect_to_mysql.php”;
$dynamicList = “”;
$sql = mysql_query(“SELECT * FROM products ORDER BY date_added”);
if(mysql_num_rows($sql) == 0) {
$dynamicList = “We have no products listed in our store yet”;
}
?>

Store Home Page
<?php include_once("template_header.php");?>
<?php if(mysql_num_rows($sql) != 0) { $position = 1; 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"])); if($position = 1) { ?> <?php if($position == 3) { echo ""; $position = 1; } else { $position++; } } $end = ""; if($position != 1){ for($z=(3-$position); $z > 0;$z--){ $end .= ""; } $end .= ""; } echo $end."

Health Category

<?=$product_name?> <?=$product_name?>
$<?=$price?>
View Product Details
"; } else { echo $dynamicList; | ?>
</div>
<?php include_once("template_footer.php");?>
[/php] replaces all your current code.

Parse error: syntax error, unexpected ‘else’ (T_ELSE) in C:\xampp\htdocs\MiriamStore\ii.php on line 262

it says last else is unexpected…

my mistake, change

} else {
echo $dynamicList;
|

to

} else {
echo $dynamicList;
}

} else \ error coming in this line
echo $dynamicList;
}

} else { \ error coming in this line
echo $dynamicList;
}

Parse error: syntax error, unexpected ‘else’ (T_ELSE) in C:\xampp\htdocs\MiriamStore\ii.php on line 177

the same error even after correcting the above

give this a try
[php]<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);

include “storescripts/connect_to_mysql.php”;
$dynamicList = “”;
$sql = mysql_query(“SELECT * FROM products ORDER BY date_added”);
if(mysql_num_rows($sql) == 0) {
$dynamicList = “We have no products listed in our store yet”;
}
?>

Store Home Page
<?php include_once("template_header.php");?>
<?php if(mysql_num_rows($sql) != 0) { $position = 1; 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"])); if($position = 1) { ?> <?php if($position == 3) { echo ""; $position = 1; } else { $position++; } } } $end = ""; if($position != 1){ for($z=(3-$position); $z > 0;$z--){ $end .= ""; } $end .= ""; } echo $end."

Health Category

<?=$product_name?> <?=$product_name?>
$<?=$price?>
View Product Details
"; } else { echo $dynamicList; } ?>
</div>
<?php include_once("template_footer.php");?>
[/php]

The line number they give in T_ELSE errors rarely contain the actual error. It just means there wasn’t a corresponding } for one of the if statements.

yeh
its done buy in a row… ok
i will correct it…

thanks richie … i dont know how i can thank you…

yeh no error
but in a row… its ok
i will correct it…

thanks richie … i dont know how i can thank you…

The example i was going off of was horribly coded, i missed the beginning

, so try this:
[php]<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);

include “storescripts/connect_to_mysql.php”;
$dynamicList = “”;
$sql = mysql_query(“SELECT * FROM products ORDER BY date_added”);
if(mysql_num_rows($sql) == 0) {
$dynamicList = “We have no products listed in our store yet”;
}
?>

Store Home Page
<?php include_once("template_header.php");?>
<?php if(mysql_num_rows($sql) != 0) { $position = 1; 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"])); if($position = 1) { echo ""; }?> <?php if($position == 3) { echo ""; $position = 1; } else { $position++; } } $end = ""; if($position != 1){ for($z=(3-$position); $z > 0;$z--){ $end .= ""; } $end .= ""; } echo $end."

Health Category

<?=$product_name?> <?=$product_name?>
$<?=$price?>
View Product Details
"; } else { echo $dynamicList; } ?>
</div>
<?php include_once("template_footer.php");?>
[/php]

Try this code out, it should work, worked for me
[php]<?php
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);

$counter = 0;
$col = 4; // number of columns

include “storescripts/connect_to_mysql.php”;
$dynamicList = “”;
$sql = mysql_query(“SELECT * FROM products ORDER BY date_added”);
if(mysql_num_rows($sql) == 0) {
$dynamicList = “We have no products listed in our store yet”;
}
?>

Store Home Page
<?php include_once("template_header.php");?>
<?php if(mysql_num_rows($sql) != 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"]));
					if($counter != 0 && $counter%$col == 0) {
						echo "</tr><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="1" /></a></td>
			<td width="83%" valign="top"><?=$product_name?><br />$<?=$price?><br /><a href="product.php?id=<?=$id?>">View Product Details</a></td>
			<?php
				$counter++;
				}
				echo "</tr></table>";
			} else {
				echo $dynamicList;
			}
		?>

</div>
<?php include_once("template_footer.php");?>
[/php]

Health Category

yes it workd thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service