473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Display database item in columns in a page

i hv created shopping cart using mysql/php. but i want to display all of my products in a table with three coloumns.. this is how my script alrdy displaying.. the page


Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. // Run a select query to get my letest 6 items
  3. // Connect to the MySQL database  
  4. include "storescripts/connect_to_mysql.php"; 
  5. $dynamicList = "";
  6. $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC");
  7. $productCount = mysql_num_rows($sql); // count the output amount
  8. if ($productCount > 0) {
  9.     while($row = mysql_fetch_array($sql)){ 
  10.              $id = $row["id"];
  11.              $product_name = $row["product_name"];
  12.              $price = $row["price"];
  13.              $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
  14.              $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
  15.         <tr>
  16.           <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>
  17.           <td width="83%" valign="top">' . $product_name . '<br />
  18.             $' . $price . '<br />
  19.             <a href="product.php?id=' . $id . '">View Product Details</a></td>
  20.         </tr>
  21.       </table>';
  22.     }
  23. } else {
  24.     $dynamicList = "We have no products listed in our store yet";
  25. }
  26. mysql_close();
  27. ?>
  28. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  29. <html xmlns="http://www.w3.org/1999/xhtml">
  30. <head>
  31. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  32. <title>Store Home Page</title>
  33. <link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
  34. </head>
  35. <body>
  36. <div align="center" id="mainWrapper">
  37.   <?php include_once("template_header.php");?>
  38.   <div id="pageContent">
  39.   <table width="100%" border="0" cellspacing="0" cellpadding="10">
  40.   <tr>
  41.     <td width="26%" valign="top"><h3>Health Category</h3>
  42.       <p><?php echo $dynamicList; ?></p>
  43.       </td>
  44.     <td width="27%" valign="top"><h3>&nbsp;</h3>
  45.       <p><?php echo $dynamicList; ?><br />
  46.         </p>
  47.       <p><br />
  48.       </p></td>
  49.     <td width="47%" valign="top"><h3>&nbsp;</h3>
  50.       <p><?php echo $dynamicList; ?>
  51.       <p><br />
  52.       </p></td>
  53.   </tr>
  54. </table>
  55.  
  56.   </div>
  57.   <?php include_once("template_footer.php");?>
  58. </div>
  59. </body>
  60. </html>
Dec 23 '12 #1
1 1712
PsychoCoder
465 Expert Mod 256MB
What's this code doing that's different than what you're wanting it to do?
Dec 23 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: yellow1912 | last post by:
Ok, lets say I have 1000 items in my database (mysql) and want to display X items per page. I learned to do it by querying with the LIMIT constrain (something like this...
3
by: SS | last post by:
Hi, I don't want to refresh a web page to query and display database. I want the page shows information immediately when database changes. What kind of technology or method would be able to...
3
by: meyo8185 | last post by:
hello guys.. i am new with javascripting and really lack of knowledge about it.. my lecturer asking me to insert or add the value that i already enter in the filed into a table locate really below...
2
by: Parasyke | last post by:
A new problem has me puzzled. I have what appears to be a very stable database but suddenly I can't find my Database Window. I tried the Startup option of Display Database Window and hit the...
1
by: Justin | last post by:
Hi all, I have a bunch of drop-down lists that should each display an item (from a SQL Server lookup table) based on another piece of data from a separate table. For example; If Not...
3
by: Steve Kershaw | last post by:
Hi, I need to display a seperate error page (off a try...catch block) in ASP.NET. Response.Redirect and Server.Transfer won't work in this case because they replace the old page with a new one...
7
by: nareshpulipati | last post by:
Hi all, I am new to VB .net. Iam trying to populate the database item into combo box. Database Type:SQL(ODBC) My code retuns no value in combo box Public Class Form1 Private Sub...
1
by: dheema | last post by:
hi, i would like to knw how to format the display of numbers from ms access database in asp page, in the database its dispalying properly but not in the asp page. i try format currency..its not...
4
by: Stefan Mueller | last post by:
Hallo I'm looking for a solution to display on a web page each second a new line. Unfortunately does the following solution not work with the Internet Explorer: ...
7
by: Surag | last post by:
Hello Guys, I have a datbase with userid,username and password. I Need to display database values in textboxes say for eg(Name and password) and redirect to login page based on the UserID please...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.