Jump to content

scronner

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Everything posted by scronner

  1. Thanks Guys, After your help and a little code bashing I discovered this works: $dynamiclist = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 2"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { $dynamiclist .= '<table width="90%" align="center"><tr>'; while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $title = $row["title"]; $author = $row["author"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamiclist .= '<td> <img src="product_images/'. $id .'.jpg" width="300" height="300" alt="'. $title .'" /><br /> '. $title .'<br /> by '. $author .'<br /> £ '. $price .' </td>'; } $dynamiclist .= '</tr></table>'; } else { $dynamiclist = "There are currently no products listed in the store"; }
  2. I'm realitivly new to PHP and was hoping somebody could help. I have a mysql database that stores information about books. I am currently using the code below to query the database and extract the 3 most recent entries and showing them in a dynamic list: $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 3"); $productCount = mysql_num_rows($sql); if ($productCount > 0) { // ensure a book exists while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $title = $row["title"]; $author = $row["author"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamiclist .= //My table showing the products } } else { $dynamicList = "There are currently no Books listed in this store"; } This works well when showing the most recent books 1 below the other. However, I would like to show these products side by side, horizontally across the page. Can somebody please point me in the right direction? Many thanks
  3. I've only been studying PHP for a week now and have come across this problem which I'm sure there is a simple answer to, but I just can't figure it out and would appreciate some help. I've spent far too long on this minor issue already! I have a table which contains a list of products, in this case books, which stores the date when each new item is added. I have a query that then searches through this table and extracts the 6 most recent additions. Here is the code I have so far: $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"]; $title = $row["title"]; $author = $row["author"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamiclist .= //My table showing the products } } else { $dynamicList = "There are currently no Books listed in this store"; } This works well when I need to display the 5 most recent products in a normal table fashion, one below another, on the page. However, I want to display the products in a more personalised order. For example display the newest item in one section of the page and 3rd newest in another. What is the best way to select an individual row from a query? To extract the details of the 2nd newest item to display in the header, for example. Thanks for your help.
×
×
  • 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.