Hi,
I'm coding in PHP4 and reading from a mySQL4 database. I have a list of products in different categories and products within categories are divided in 3 ways (for displaying them). One of the fields on the products table is listtype and this can be set to 1, 2 or 3.
If listtype is set to 1, the product will display as normal. With a picture, a title, a description and a price as well as an 'ADD TO CART' button.
If listtype is set to 2, the product will display as a header for the drop down list. This will display a picture, a title and a description but no 'ADD TO CART' button.
If listtype is set to 3, the product will display as an item in a drop down list. (if it is the first of listtype 3 it starts the <select> statement). It then displays the description and the price. I want to be able to add these products to the cart...
And that is where my problem lies. Can I somehow add an 'ADD TO CART' button that will add whatever is selected to my cart??
So you can understand a little more how this works, the query for loading the products in a category, sorts the products by title and then by productid. When adding products, a dropdown list must be preceded by a product header and the product titles must be equal to all other products in the drop down list as well as the preceding product header. All products in the drop down list must have a product id greater than that of the product header it will be following.
OK - here's the code:
function display_products($product_array)
{
//display all products in the array passed in
if (!is_array($product_array))
{
echo '<br />No products currently available in this category<br />';
}
else
{
//create table
echo '<table width = \"100%\" border = 0>';
//create a table row for each product
// $lastrow = $row['listtype'];
foreach ($product_array as $row)
{
if (($lastrow == '3') && ($row['listtype'] != '3'))
{
echo '</select></td>';
echo '<td>';
display_button2('show_cart.php?new='.($row['productid']), 'add-to-cart', 'Add '
.$row['title'].' To My Quotation');
echo '</td></tr>';
}
$url = 'show_product.php?productid='.($row['productid']);
if ($row['listtype'] == '1')
{
echo '<tr><td>';
if (@file_exists('images/'.$row['productid'].'.jpg'))
{
$title = '<img src=\'images/'.($row['productid']).'.jpg\' border=0 />';
do_html_url($url, $title);
}
else
{
echo ' ';
}
echo '</td><td>';
$title = $row['title'].' by '.$row['manufacturer'];
do_html_url($url, $title);
echo '</td>';
echo '<td> </td><td>';
display_button2('show_cart.php?new='.($row['productid']), 'add-to-cart', 'Add '
.$row['title'].' To My Quotation');
echo '</td></tr>';
$lastrow = $row['listtype'];
}
elseif ($row['listtype'] == '2')
{
echo '<tr><td>';
if (@file_exists('images/'.$row['productid'].'.jpg'))
{
$title = '<img src=\'images/'.($row['productid']).'.jpg\' border=0 />';
do_html_url($url, $title);
}
else
{
echo ' ';
}
echo '</td><td>';
echo $row['title'];
echo '<br>';
echo $row['description'];
echo '</td>';
echo '<td> </td><td>';
echo '</td></tr>';
$lastrow = $row['listtype'];
}
elseif ($row['listtype'] == '3')
{
if ($lastrow == '2')
{
echo '<tr><td> </td><td>';
echo '<select size="1"><option value="';
echo $row['productid'];
echo '">';
echo $row['description'];
$lastrow = $row['listtype'];
}
elseif ($lastrow == '3')
{
echo '<option value="';
echo $row['productid'];
echo '">';
echo $row['description'];
$lastrow = $row['listtype'];
}
}
}
echo '</table>';
}
echo '<hr />';
}
And this is the code for the display_button2 function:
function display_button2($target, $image, $alt)
{
echo '<center><a href=';
echo $target;
echo ' target="iframecart"><img src= "images\\';
echo $image;
echo '.gif"';
echo "alt=\"$alt\" border=0 height = 50 width = 135></a></center>";
}
Thanks in advance for any guidance and help. If there is anything else I can provide or explain please let me know - I hope it all makes sense.
Thanks again
Sheldon