HTML/CSS formatting of mysql data retrieved by PHP

I’m working on an e-commerce site for a client of mine. I’m building a mysql product database and want to retrieve the info from the database via php and then format for html so my css style sheet can be applied.

Currently, I’m hard-coding all of the products as such:

$12.00
Azul Luau
1" Blue Chica Band with White Hibiscus Flowers

That’s the code for 1 product listed on a single page. This site has over 400 products spread over 10 pages and some of them appear on multiple pages. Since they’re currently hard-coded, it’s a nightmare when updating, adding, and removing products. I’d like to be able to run a query like “select * from products_master where solid = 1 and date_removed is null; order by title”

Fields I need to build the code above and can pull from the database are as follows: image (stored as image location such as “images/cb361.gif”), price (stored as double-decimal such as “12.00”), title (stored as product title such as “Dreaming of Palm Trees”), description (self explanatory), and button (stored as the google add-to-cart button).

How would I do this in php code, nested inside a div tag, within an html document?

Need to get to this format:

PRICEGOESHERE
TITLEGOESHERE
DESCRIPTIONGOESHERE
<BUTTONSTRINGGOESHERE

…is this possible with php? if so, can someone please help? Thanks in advance for any and all replies.

Here is the php code for your example:
[php]<?php
// connecting to MySQL server
$mysqlink=mysql_connect(‘localhost’,‘user_name’,‘user_passw’) or die(mysql_error());

// selecting database
mysql_select_db(‘db_name’,$mysqlink);

// querying products
$r = mysql_query(“select * from products_master where solid = 1 and date_removed is null order by title”);
if(mysql_num_rows($r)){
for($i=0;$i<mysql_num_rows($r);$i++){ // loop for all products returned by query…
$f=mysql_fetch_array($r);

  // displaying one product
  echo '<div class="space"></div>
$'.sprintf("%01.2f",$f["price"]).'
'.$f["title"].'
'.$f["description"].'
'.$f["button"].'
';
}

}
else{
echo ‘

No products found.

’;
}
?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service