Hey, now I have a new problem. Working on an existing site, I’m copying over codes and this code for the page that used to show the items in their cart and the total including shipping, is not working. Is the entire thing all screwed up? Does anyone know?
[code=php]<?php
function do_html_URL($url, $name)
{
?>
<a href=”<?php echo $url; ?>”><?php echo $name; ?></a><br />
<?php
}
function display_categories($cat_array)
{
if (!is_array($cat_array))
{
echo ‘No categories currently available<br />’;
return;
}
echo ‘<ul>’;
foreach ($cat_array as $row)
{
$url = ‘show_cat.php?catid=’.($row[‘catid’]);
$title = $row[‘catname’];
echo ‘<li>’;
do_html_url($url, $title);
}
echo ‘</ul>’;
echo ‘<hr />’;
}
function display_products($array)
{
if (!is_array($array))
{
echo ‘<p style=”font: 12px/150% Arial, Verdana;”>No products currently available in this category</p>’;
}
else
{
//create table
echo ‘<table width = “100%” border = “0” cellpadding=”0″ cellspacing=”0″ align = “center”>’;
//create a table row for each ergopad
$row_counter = 0;
foreach ($array as $row)
{
$url = ‘show_product.php?product_id=’.($row[‘product_id’]);
if ($row_counter != 1)
{
echo ‘<tr>’;
}
echo ‘<td style=”font: 12px Arial, Verdana; text-align: center; padding-bottom: 5px; padding-top: 15px; border: 1px solid #efefef;”>’;
if (@file_exists(‘images/’.$row[‘product_id’].’.gif’))
{
$title = ‘<img src=’images/’.($row[‘product_id’]).’.gif’ border=0>’;
do_html_url($url, $title);
}
else
{
echo ‘ ’;
}
echo ‘<br />’;
$title = $row[‘product_name’];
do_html_url($url, $title);
if($row_counter == 1)
{
echo ‘</tr>’;
$row_counter = 0;
}
else{
echo ‘</td>’;
$row_counter++;
}
}
echo ‘</table><br /><br />’;
}
}
function display_product_details($product)
{
// display all details about this product
if (is_array($product))
{
echo ‘<table><tr>’;
//display the picture if there is one
if (@file_exists(‘images/’.($product[‘product_id’]).’.gif’))
{
$size = GetImageSize(‘images/’.$product[‘product_id’].’.gif’);
if($size[0]>0 && $size[1]>0)
echo ‘<td><img src=’images/’.$product[‘product_id’].’.gif’ border=0 ‘.$size[3].’></td>’;
}
echo ‘<td><ul style=”font: 12px/150% Arial, Verdana;”>’;
echo ‘<b>’.$product[‘product_name’].'</b>’;
echo ‘<li><b>Stock Number:</b> ‘;
echo $product[‘product_id’];
echo ‘<li><b>Description:</b> ‘;
echo $product[‘description’];
echo ‘<li><b>Price:</b><br /> ‘;
echo $product[‘country_name’].” ”;
echo number_format($product[‘price’], 2);
echo ‘</ul></td></tr></table>’;
echo ‘<hr /><br />’;
}
}
function display_shipping($shipping)
{
?>
<table border = “0” width = “100%” cellspacing = “0”>
<tr><td align = “left”>Shipping</td>
<td align = “right”>$<?php echo number_format($shipping, 2); ?> </td></tr>
<tr><th bgcolor=”#cccccc” align = “left”>TOTAL </th>
<th bgcolor=”#cccccc” align = “right”>$<?php echo number_format($shipping+$_SESSION[‘total_price’], 2); ?> </th>
</tr>
</table><br />
<?php
}
function display_cart($cart, $change = true, $images = 0)
{
// display items in shopping cart
// optionally allow changes (true or false)
// optionally include images (1 – yes, 0 – no)
echo ‘<table border = 0 width = 100% cellspacing = 0>
<form action = “show_cart.php” method = “post”>
<tr align = “center”><th colspan = ‘. (1+$images) .’ bgcolor=”#cccccc”>Item</th>
<th bgcolor=”#cccccc”>Price</th><th bgcolor=”#cccccc”>Quantity</th>
<th bgcolor=”#cccccc”>Total</th></tr>’;
//display each item as a table row
foreach ($cart as $product_id => $qty)
{
$product = get_product_details($product_id);
echo ‘<tr>’;
if($images ==true)
{
echo ‘<td align = left>’;
if (file_exists(“images/$product_id.gif”))
{
$size = GetImageSize(‘images/’.$product_id.’.gif’);
if($size[0]>0 && $size[1]>0)
{
echo ‘<img src=”images/’.$product_id.’.gif” border=0 ‘;
echo ‘width = ‘. $size[0]/3 .’ height = ‘ .$size[1]/3 . ‘>’;
}
}
else
echo ‘ ’;
echo ‘</td>’;
}
echo ‘<td align = center>’;
echo ‘<a href = “show_product.php?product_id=’.$product_id.'”>’.$product[‘description’].'</a>’;
echo ‘</td><td align = center>$’.number_format($product[‘price’], 2);
echo ‘</td><td align = center> ’;
// if we allow changes, quantities are in text boxes
if ($change == true)
echo “<input type = text style = “text-align: right”; name = “$product_id” value = “$qty” size = 3>”;
else
echo $qty;
echo ‘</td><td align = center>$’.number_format($product[‘price’]*$qty,2).”</td></tr>n”;
}
// display total row
echo ‘<tr>
<th colspan = ‘. (2+$images) .” bgcolor=”#cccccc”> </td>
<th align = “center” bgcolor=”#cccccc”> ”.$_SESSION[‘items’].”
</th>
<th align = “center” bgcolor=”#cccccc”>
$”.number_format($_SESSION[‘total_price’], 2).
‘</th>
</tr>’;
// display save change button
if($change == true)
{
echo ‘<tr>
<td colspan = ‘. (2+$images) .’> </td>
<td align = center>
<br />
<input type = “hidden” name = “save” value = “true”>
<input type = “image” src = “images/save-changes.jpg” border = 0 alt = “Save Changes”>
</td>
<td> </td>
</tr>’;
}
echo ‘</form></table>’;
}