arunpatal Posted November 7, 2012 Share Posted November 7, 2012 Hi, In this code each product shows vertical in line, Pic text Pic text I want to show my Products item in horizontal line. Pic Pic Pic text text text can please someone look into it Thanks <?php include "storescripts/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10"); $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="154" border="0" cellspacing="0" cellpadding="6"> <td width="142" valign="top" align="center"><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><p>' . $product_name . '</td> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/ Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 You should to add outside th while loop to add: echo '<table><tr>'; And code before loop: echo '<table><tr>'; And delete table tags (start and end tag) from the $dynamicList variable. Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390685 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 You should to add outside th while loop to add: echo '<table><tr>'; And code before loop: echo '<table><tr>'; And delete table tags (start and end tag) from the $dynamicList variable. Thanks but i am very new..... can you please tell me which line to change? should i paste complete page coding? Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390687 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 I removed table tag but i can not Understand (You should to add outside th while loop to add: echo '<table><tr>'; And code before loop: echo '<table><tr>' <?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 10"); $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 .= '<td width="142" valign="top" align="center"><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><p>' . $product_name . '</td>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390690 Share on other sites More sharing options...
thara Posted November 7, 2012 Share Posted November 7, 2012 your table have a problem... you can do it something like this.. // print table heading before start while loop echo '<table align="center" cellspacing="3" cellpadding="3" width="100%"> <tr> <td align="left"><b>Product Name</b></td> <td align="left"><b>Price</b></td> <td align="left"><b>Added Date</b></td> </tr>'; In while loop.. you need to echo table body.. like this echo '<tr><td align="left">' . $row["product_name"] . '</td> <td align="left">' . $row["price"] . '</td> <td align="left">' . $row["date_added"] . '</td> </tr>'; after while loop.. close the table echo '</table>'; // Close the table. Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390691 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 This is the complete code. Please check.... <?php // This file is www.developphp.com curriculum material // Written by Adam Khoury January 01, 2011 // http://www.youtube.com/view_play_list?p=442E340A42191003 // Script Error Reporting 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 6"); $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="0" cellspacing="0" cellpadding="6"> <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> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="32%" valign="top"><h3>What the Hell?</h3> <p>This website is very temporarily being used as an online live showcase area for an E - Commerce tutorial script set Adam is creating which can be seen on his channel here:<br /> <a href="http://www.youtube.com/flashbuilding" target="_blank">http://www.youtube.com/flashbuilding</a> </p> <p>It is not an actual store and it will change directly after the tutorial series. <br /> <br /> This tutorial series is for educational purposes only. Use the scripts at your own risk.</p></td> <td width="35%" valign="top"><h3>Latest Designer Fashions</h3> <p><?php echo $dynamicList; ?><br /> </p> <p><br /> </p></td> <td width="33%" valign="top"><h3>Handy Tips</h3> <p>If you operate any store online you should read the documentation provided to you by the online payment gateway you choose for handling the checkout process. You can get much more insight than I can offer on the various details of a gateway, from the gateway providers themselves. They are there to help you with whatever you need since they get a cut of your online business dealings.</p></td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390693 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 (edited) Your code become from initial to: <?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 10"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { echo '<table><tr>'; 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 .= '<td width="142" valign="top" align="center"><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><p>' . $product_name . '</td>'; } echo '</tr></table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Now you should to check it Edited November 7, 2012 by Volter9 Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390694 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 Your code become from initial to: <?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 10"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { echo '<table><tr>'; 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 .= '<td width="142" valign="top" align="center"><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><p>' . $product_name . '</td>'; } echo '</tr></table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Now you should to check it Its geting outside the table check link blow http://arunpatal.host-ed.me/Untitled.png Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390696 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 (edited) Its geting outside the table check link blow http://arunpatal.hos...me/Untitled.png Then: <?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 10"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { echo '<table>'; while($row = mysql_fetch_array($sql)){ if (($productCount % 5) == 0) echo '<tr>'; } $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<td width="142" valign="top" align="center"><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><p>' . $product_name . '</td>'; if (($productCount % 5) == 0) echo '</tr>'; } } echo '</table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> if it's still going outside the table then change "... % 5" to "... % 4" Edited November 7, 2012 by Volter9 Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390697 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) Then: <?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 10"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { echo '<table>'; while($row = mysql_fetch_array($sql)){ if (($productCount % 5) == 0) echo '<tr>'; } $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<td width="142" valign="top" align="center"><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><p>' . $product_name . '</td>'; if (($productCount % 5) == 0) echo '</tr>'; } } echo '</table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> if it's still going outside the table then change "... % 5" to "... % 4" } (error) echo '</table>'; } else { (error) There is error in these two line..... can you please check... Thanks a lot Edited November 7, 2012 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390698 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 There is error in these two line..... can you please check... Thanks a lot I cannot help without link to your site, if it's localhost I'll try to format code, try now: <?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 10"); $productCount=mysql_num_rows($sql); // count the output amount if($productCount>0) { echo '<table>'; while($row=mysql_fetch_array($sql)) { if(($productCount%5)==0) { echo '<tr>'; } $id=$row["id"]; $product_name=$row["product_name"]; $price=$row["price"]; $date_added=strftime("%b %d, %Y",strtotime($row["date_added"])); $dynamicList.='<td width="142" valign="top" align="center"><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><p>'.$product_name.'</td>'; if(($productCount%5)==0) { echo '</tr>'; } } echo '</table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390699 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 Please check this site... http://arunpatal.host-ed.me/ Its still like that Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390701 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 Ok, I get it: <?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 10"); $productCount=mysql_num_rows($sql); // count the output amount if($productCount>0) { echo '<table>'; while($row=mysql_fetch_array($sql)) { if(($productCount%5) == 0) { $dynamicList .= '<tr>'; } $id=$row["id"]; $product_name=$row["product_name"]; $price=$row["price"]; $date_added=strftime("%b %d, %Y",strtotime($row["date_added"])); $dynamicList.='<td width="142" valign="top" align="center"><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><p>'.$product_name.'</td>'; if(($productCount%5)==4) { $dynamicList .= '</tr>'; } } echo '</table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390704 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 No.... can you check page again.... http://arunpatal.host-ed.me/ Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390706 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) The complete page coding is like this according to your editing........ <?php // Script Error Reporting 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 10"); $productCount=mysql_num_rows($sql); // count the output amount if($productCount>0) { echo '<table>'; while($row=mysql_fetch_array($sql)) { if(($productCount%5) == 0) { $dynamicList .= '<tr>'; } $id=$row["id"]; $product_name=$row["product_name"]; $price=$row["price"]; $date_added=strftime("%b %d, %Y",strtotime($row["date_added"])); $dynamicList.='<td width="142" valign="top" align="center"><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><p>'.$product_name.'</td>'; if(($productCount%5)==4) { $dynamicList .= '</tr>'; } } echo '</table>'; } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Store Home Page</title> <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" /> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("template_header.php");?> <div id="pageContent"> <table width="100%" border="0" cellspacing="0" cellpadding="10"> <tr> <td width="35%" valign="top"><h3><?php echo $dynamicList; ?><br /> </h3> <p><br /> </p></td> <td width="33%" valign="top"><h3>Handy Tips</h3> <p>If you operate any store online you should read the documentation provided to you by the online payment gateway you choose for handling the checkout process. You can get much more insight than I can offer on the various details of a gateway, from the gateway providers themselves. They are there to help you with whatever you need since they get a cut of your online business dealings.</p></td> </tr> </table> </div> <?php include_once("template_footer.php");?> </div> </body> </html> Edited November 7, 2012 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390708 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 How many rows you have in data base? Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390709 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 This is the Product table <?php // Connect to the file above here require "connect_to_mysql.php"; $sqlCommand = "CREATE TABLE products ( id int(11) NOT NULL auto_increment, product_name varchar(255) NOT NULL, price varchar(16) NOT NULL, details text NOT NULL, category varchar(16) NOT NULL, subcategory varchar(16) NOT NULL, date_added date NOT NULL, PRIMARY KEY (id), UNIQUE KEY product_name (product_name) )"; if(mysql_query($sqlCommand)){ echo "Your products table has been created successfully!"; }else { echo "CRITICAL ERROR: products table has not been created"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390710 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 Hi Volter, Will it be possible for you to check the script if i PM you the hosting details? Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390713 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 (edited) Ok, how many rows in products table... Simpler question: what did you get in $productCount variable? P.S.: OK, but if you promise that you will change password. OK? Edited November 7, 2012 by Volter9 Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390714 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) I promise I have send you PM Edited November 7, 2012 by arunpatal Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390715 Share on other sites More sharing options...
arunpatal Posted November 7, 2012 Author Share Posted November 7, 2012 Hi, In this code each product shows vertical in line, Pic text Pic text I want to show my Products item in horizontal line. Pic Pic Pic text text text can please someone look into it Thanks <?php include "storescripts/connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 10"); $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="154" border="0" cellspacing="0" cellpadding="6"> <td width="142" valign="top" align="center"><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><p>' . $product_name . '</td> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390728 Share on other sites More sharing options...
Volter9 Posted November 7, 2012 Share Posted November 7, 2012 Ok, I fix it... Enjoy Quote Link to comment https://forums.phpfreaks.com/topic/270388-layout/#findComment-1390859 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.