PDA

View Full Version : Lost with a shopping cart


harlequin2k5
09-04-2006, 06:19 AM
ok - the site is here (http://test.buymesomethingpretty.com/index4.php)

I realize it's not as pretty in ie as it is in ff but I'll worry about that later

each of the pages in the shopping cart use functions that go back to a central page of functions...

main functions
<?php

function do_html_header($title = '')
{
// print an HTML header

// declare the session variables we want access to inside the function
if(!$_SESSION['items']) $_SESSION['items'] = '0';
if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00';
?>
<html>
<head>
<title><?php echo 'Buy Me Something Pretty - ';echo $title; ?></title>
<link href="css/main2.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="iestyle.css" type="text/css" />
<![endif]-->
</head>
<body>
<table width='100%' border=0 cellspacing=0 bgcolor="#359a8f">
<tr>
<td rowspan = 2>&nbsp;</td>
<td align = 'right' valign = 'bottom'>
<?php if(isset($_SESSION['admin_user']))
echo '&nbsp;';
else
echo 'Total Items = '.$_SESSION['items'];
?>
</td>
<td align = 'right' rowspan = 2 width = 135>
<?php if(isset($_SESSION['admin_user']))
display_button('logout.php', 'log-out', 'Log Out');
else
display_button('show_cart.php', 'view-cart', 'View Your Shopping Cart');
?>
</tr>
<tr>
<td align = right valign = top>
<?php if(isset($_SESSION['admin_user']))
echo '&nbsp;';
else
echo 'Total Price = $'.number_format($_SESSION['total_price'],2);
?>
</td>
</tr>
</table>
<?php
if($title)
do_html_heading($title);
}

function do_html_footer()
{
// print an HTML footer
?>
<div class="clearfix"></div></div></body>
</html>
<?php
}

function do_html_heading($heading)
{
// print heading
?>
<h2><?php echo $heading; ?></h2>
<?php
}

function do_html_URL($url, $name)
{
// output URL as link and br
?>
<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><li class="listtitle">Categories</li>';
foreach ($cat_array as $row)
{
$url = 'show_cat.php?catid='.($row['catid']);
$title = $row['catname'];
echo '<li>';
do_html_url($url, $title);
echo '</li>';
}
echo '</ul></div><div id="main-content-container">
<div id="right-col-container"><img src="images/GirlNoBag-right.jpg" class="girlimageclass" alt="" /></div>
<div id="content">
<p>Select a category on the left to see all of the catalog items.</p></div></div>
';
}

function display_items($item_array)
{
//display all items in the array passed in
if (!is_array($item_array))
{
echo '<br />No items currently available in this category<br />';
}
else
{
//create table
echo '<table width = \"100%\" border = 0>';

//create a table row for each item
foreach ($item_array as $row)
{
$url = 'show_book.php?itemno='.($row['itemno']);
echo '<tr><td>';
if (@file_exists('images/catalog'.$row['itemno'].'.gif'))
{
$title = '<img src=\'images/catalog'.($row['itemno']).'.gif\' border=0 />';
do_html_url($url, $title);
}
else
{
echo '&nbsp;';
}
echo '</td><td>';
$shortdesc = $row['shortdescription'];
do_html_url($url, $shortdesc);
echo '</td></tr>';
}
echo '</table>';
}
echo '<hr />';
}

function display_item_details($item)
{
// display all details about this book
if (is_array($item))
{
echo '<table><tr>';
//display the picture if there is one
if (@file_exists('images/'.($item['itemno']).'.gif'))
{
$size = GetImageSize('images/'.$item['itemno'].'.gif');
if($size[0]>0 && $size[1]>0)
echo '<td><img src=\'images/'.$book['itemno'].'.gif\' border=0 '.$size[3].'></td>';
}
echo '<td><ul>';
echo '<li><b>Author:</b> ';
echo $item['itemno'];
echo '</li><li><b>ISBN:</b> ';
echo $item['shortdescription'];
echo '</li><li><b>Our Price:</b> ';
echo number_format($item['retailprice'], 2);
echo '</li><li><b>Description:</b> ';
echo $item['longdescription'];
echo '</li></ul></td></tr></table>';
}
else
echo 'The details of this item cannot be displayed at this time.';
echo '<hr />';
}

function display_checkout_form()
{
//display the form that asks for name and address
?>
<br />
<table border = 0 width = '100%' cellspacing = 0>
<form action = 'purchase.php' method = 'post'>
<tr><th colspan = 2 bgcolor='#cccccc'>Your Details</th></tr>
<tr>
<td>Name</td>
<td><input type = 'text' name = 'name' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Address</td>
<td><input type = 'text' name = 'address' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type = 'text' name = 'city' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type = 'text' name = 'state' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type = 'text' name = 'zip' value = "" maxlength = 10 size = 40></td>
</tr>
<tr>
<td>Country</td>
<td><input type = 'text' name = 'country' value = "" maxlength = 20 size = 40></td>
</tr>
<tr><th colspan = 2 bgcolor='#cccccc'>Shipping Address (leave blank if as above)</th></tr>
<tr>
<td>Name</td>
<td><input type = 'text' name = 'ship_name' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Address</td>
<td><input type = 'text' name = 'ship_address' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type = 'text' name = 'ship_city' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type = 'text' name = 'ship_state' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type = 'text' name = 'ship_zip' value = "" maxlength = 10 size = 40></td>
</tr>
<tr>
<td>Country</td>
<td><input type = 'text' name = 'ship_country' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td colspan = 2 align = 'center'>
<b>Please press Purchase to confirm your purchase,
or Continue Shopping to add or remove items</b>
<?php display_form_button('purchase', 'Purchase These Items'); ?>
</td>
</tr>
</form>
</table><hr />
<?php
}

function display_shipping($shipping)
{
// display table row with shipping cost and total price including 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 INCLUDING SHIPPING</th>
<th bgcolor='#cccccc' align = 'right'>$<?php echo number_format($shipping+$_SESSION['total_price'], 2); ?></th>
</tr>
</table><br />
<?php
}

function display_card_form($name)
{
//display form asking for credit card details
?>
<table border = 0 width = '100%' cellspacing = 0>
<form action = 'process.php' method = 'post'>
<tr><th colspan = 2 bgcolor="#cccccc">Credit Card Details</th></tr>
<tr>
<td>Type</td>
<td><select name = 'card_type'><option>VISA<option>MasterCard<option>American Express</select></td>
</tr>
<tr>
<td>Number</td>
<td><input type = 'text' name = 'card_number' value = "" maxlength = 16 size = 40></td>
</tr>
<tr>
<td>AMEX code (if required)</td>
<td><input type = 'text' name = 'amex_code' value = "" maxlength = 4 size = 4></td>
</tr>
<tr>
<td>Expiry Date</td>
<td>Month <select name = 'card_month'><option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10<option>11<option>12</select>
Year <select name = 'card_year'><option>00<option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10</select></td>
</tr>
<tr>
<td>Name on Card</td>
<td><input type = 'text' name = 'card_name' value = "<?php echo $name; ?>" maxlength = 40 size = 40></td>
</tr>
<tr>
<td colspan = 2 align = 'center'>
<b>Please press Purchase to confirm your purchase,
or Continue Shopping to add or remove items</b>
<?php display_form_button('purchase', 'Purchase These Items'); ?>
</td>
</tr>
</table>
<?php
}



function display_cart($cart, $change = true, $images = 1)
{
// 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><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 $isbn => $qty)
{
$book = get_book_details($isbn);
echo '<tr>';
if($images ==true)
{
echo '<td align = left>';
if (file_exists("images/$isbn.jpg"))
{
$size = GetImageSize('images/'.$isbn.'.jpg');
if($size[0]>0 && $size[1]>0)
{
echo '<img src="images/'.$isbn.'.jpg" border=0 ';
echo 'width = '. $size[0]/3 .' height = ' .$size[1]/3 . ' />';
}
}
else
echo '&nbsp;';
echo '</td>';
}
echo '<td align = "left">';
echo '<a href = "show_book.php?isbn='.$isbn.'">'.$book['title'].'</a> by '.$book['author'];
echo '</td><td align = "center">$'.number_format($book['price'], 2);
echo '</td><td align = "center">';
// if we allow changes, quantities are in text boxes
if ($change == true)
echo "<input type = 'text' name = \"$isbn\" value = \"$qty\" size = 3>";
else
echo $qty;
echo '</td><td align = "center">$'.number_format($book['price']*$qty,2)."</td></tr>\n";
}
// display total row
echo "<tr>
<th colspan = ". (2+$images) ." bgcolor=\"#cccccc\">&nbsp;</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) .'>&nbsp;</td>
<td align = "center">
<input type = "hidden" name = "save" value = true>
<input type = "image" src = "images/save-changes.gif"
border = 0 alt = "Save Changes">
</td>
<td>&nbsp;</td>
</tr>';
}
echo '</form></table>';
}

function display_login_form()
{
// dispaly form asking for name and password
?>
<form method='post' action="admin.php">
<table bgcolor='#cccccc'>
<tr>
<td>Username:</td>
<td><input type='text' name='username'></td></tr>
<tr>
<td>Password:</td>
<td><input type='password' name='passwd'></td></tr>
<tr>
<td colspan=2 align='center'>
<input type='submit' value="Log in"></td></tr>
<tr>
</table></form>
<?php
}

function display_admin_menu()
{
?>
<br />
<a href="index.php">Go to main site</a><br />
<a href="insert_category_form.php">Add a new category</a><br />
<a href="insert_book_form.php">Add a new book</a><br />
<a href="change_password_form.php">Change admin password</a><br />
<?php

}

function display_button($target, $image, $alt)
{
echo "<center><a href=\"$target\"><img src=\"images/$image".".gif\"
alt=\"$alt\" border=0 height = 50 width = 135></a></center>";
}

function display_form_button($image, $alt)
{
echo "<center><input type = image src=\"images/$image".".gif\"
alt=\"$alt\" border=0 height = 50 width = 135></center>";
}

?>


index page
<?php
include ('book_sc_fns.php');
// The shopping cart needs sessions, so start one
echo ' <div id="main-wrap"><a href="index.php"><img src="images/buybanner.jpg" alt="Return to BuyMeSomethingPretty.com" class="headerimage" /></a>
';
session_start();
do_html_header('Welcome');

echo '<div id="left-col-container">';

// get categories out of database
$cat_array = get_categories();

// display as links to cat pages
display_categories($cat_array);

// if logged in as admin, show add, delete, edit cat links
if(isset($_SESSION['admin_user']))
{
display_button('admin.php', 'admin-menu', 'Admin Menu');
}
do_html_footer();
?>


categories page
<?php
include ('book_sc_fns.php');
// The shopping cart needs sessions, so start one
echo ' <div id="main-wrap"><a href="index.php"><img src="images/buybanner.jpg" alt="Return to BuyMeSomethingPretty.com" class="headerimage" /></a>
';
session_start();
do_html_header('Welcome');

echo '<div id="left-col-container">';

// get categories out of database
$cat_array = get_categories();

// display as links to cat pages
display_categories($cat_array);

// if logged in as admin, show add, delete, edit cat links
if(isset($_SESSION['admin_user']))
{
display_button('admin.php', 'admin-menu', 'Admin Menu');
}
do_html_footer();
?>


one of the things I'd like to accomplish is to have the categories in the left column of index4.php to show in show_cat.php

the original design is here (http://test.buymesomethingpretty.com) and obviously I'd like to keep the entire site looking the same

any help would be greatly appreciated :)

Brandoe85
09-04-2006, 07:28 AM
Looks like this is the part that does it?

echo '<div id="left-col-container">';

// get categories out of database
$cat_array = get_categories();


Try adding that to the categories page.

harlequin2k5
09-04-2006, 08:53 PM
ok...I finally got the left-col-container to display (http://test.buymesomethingpretty.com/show_cat.php?catid=3) but I can't get the categories to display...these are the 2 functions

function display_categories($cat_array)
{
if (!is_array($cat_array))
{
echo 'No categories currently available<br />';
return;
}
echo '<div id="left-col-container"><ul><li class="listtitle">Categories</li>';
foreach ($cat_array as $row)
{
echo '<li>';
$url = 'show_cat.php?catid='.($row['catid']);
$title = $row['catname'];
do_html_url($url, $title);
echo '</li>';
}
echo '</ul></div>
<div id="right-col-container"><img src="images/GirlNoBag-right.jpg" class="girlimageclass" alt="" /></div>
<div id="main-content-container"><div id="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis ligula lorem,
consequat eget, tristique nec, auctor quis, purus. Vivamus ut sem. Fusce aliquam
nunc vitae purus. Aenean viverra malesuada libero. Fusce ac quam. Donec neque.
Nunc venenatis enim nec quam. Cras faucibus, justo vel accumsan aliquam, tellus
dui fringilla quam, in condimentum augue lorem non tellus. Pellentesque id arcu
non sem placerat iaculis. Curabitur posuere, pede vitae lacinia accumsan, enim
nibh elementum orci, ut volutpat eros sapien nec sapien. Suspendisse neque arcu,
ultrices commodo, pellentesque sit amet, ultricies ut, ipsum. Mauris et eros
eget erat dapibus mollis. Mauris laoreet posuere odio. Nam ipsum ligula, ullamcorper
eu, fringilla at, lacinia ut, augue. Nullam nunc.</p>
';
}

function display_items($item_array)
{
//display all books in the array passed in
if (!is_array($item_array))
{
echo '<br />No items currently available in this category<br />';
}
else
{
//create table
echo '<div id="left-col-container"><ul><li class="listtitle">Categories</li>';
echo '<li>';
$url = 'show_cat.php?catid='.($row['catid']);
$title = $row['catname'];
do_html_url($url, $title);
echo '</li>';
echo '</ul></div>';
echo '<div id="right-col-container"><img src="images/GirlNoBag-right.jpg" class="girlimageclass" alt="" /></div>
<div id="main-content-container"><div id="content"><div id="contentimages"><ul>';

//create a table row for each book
foreach ($item_array as $row)
{
$url = 'show_book.php?itemno='.($row['itemno']);
echo '<li class="itemimage">';
if (@file_exists('images/catalog/'.$row['itemno'].'.gif'))
{
$title = '<img src=\'images/catalog/'.($row['itemno']).'.gif\' border=0 />';
do_html_url($url, $title);
}
else
{
echo '<br />';
}
$title = $row['title'].$row['shortdescription'];
do_html_url($url, $title);
echo '</li>';
}
echo '</ul></div>';
}
echo '<div class="clearfix"></div>
<hr />';
}


any help as always is greatly appreciated...

Brandoe85
09-04-2006, 10:29 PM
Where/what is get_categories()? Looks to me you need to call that first:
$cat_array = get_categories();

An pass $cat_array to display_categories($cat_array)

Good luck;

harlequin2k5
09-04-2006, 11:09 PM
thanks brandoe85

after 3 days I'm still lost - time to move on to something else

Brandoe85
09-04-2006, 11:12 PM
You can't give up so easy! :)

harlequin2k5
09-05-2006, 01:04 AM
care to take some time to help me with this? :)

Brandoe85
09-05-2006, 01:13 AM
Sure :), did you give my idea a go? Find the get_categories() function?

harlequin2k5
09-05-2006, 01:45 AM
as a matter of fact I didn't :(

this is the show_cat.php

<?php
include ('book_sc_fns.php');
// The shopping cart needs sessions, so start one
session_start();

$catid = $_GET['catid'];
$name = get_category_name($catid);

do_html_header($name);

// get the book info out from db
$item_array = get_items($catid);

display_items($item_array);

// if logged in as admin, show add, delete book links
if(isset($_SESSION['admin_user']))
{
display_button('index.php', 'continue', 'Continue Shopping');
display_button('admin.php', 'admin-menu', 'Admin Menu');
display_button("edit_category_form.php?catid=$catid",
'edit-category', 'Edit Category');
}
else
display_button('index.php', 'continue-shopping', 'Continue Shopping');

do_html_footer();
?>


this is the output_fns.php

<?php

function do_html_header($title = '')
{
// print an HTML header

// declare the session variables we want access to inside the function
if(!$_SESSION['items']) $_SESSION['items'] = '0';
if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="eng-us">
<head>
<title><?php echo 'Buy Me Something Pretty - ';echo $title; ?></title>
<link href="css/main2.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link rel="stylesheet" href="iestyle.css" type="text/css" />
<![endif]-->
</head>
<body>
<div id="main-wrap"><a href="index.php"><img src="images/buybanner.jpg" alt="Return to BuyMeSomethingPretty.com" class="headerimage" /></a>
<table width='100%' border=0 cellspacing = 0 bgcolor='#359a8f'>
<tr>
<td rowspan = 2>
</td>
<td align = 'right' valign = 'bottom'>
<?php if(isset($_SESSION['admin_user']))
echo '&nbsp;';
else
echo 'Total Items = '.$_SESSION['items'];
?>
</td>
<td align = 'right' rowspan = 2 width = 135>
<?php if(isset($_SESSION['admin_user']))
display_button('logout.php', 'log-out', 'Log Out');
else
display_button('show_cart.php', 'view-cart', 'View Your Shopping Cart');
?>
</tr>
<tr>
<td align = right valign = top>
<?php if(isset($_SESSION['admin_user']))
echo '&nbsp;';
else
echo 'Total Price = $'.number_format($_SESSION['total_price'],2);
?>
</td>
</tr>
</table>
<?php
if($title)
do_html_heading($title);
}

function do_html_footer()
{
// print an HTML footer
?>
</div></div><div class="clearfix"></div></div></body>
</html>
<?php
}

function do_html_heading($heading)
{
// print heading
?><h2>&nbsp;</h2>
<?php
}

function do_html_URL($url, $name)
{
// output URL as link and br
?>
<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 '<div id="left-col-container"><ul><li class="listtitle">Categories</li>';
foreach ($cat_array as $row)
{
echo '<li>';
$url = 'show_cat.php?catid='.($row['catid']);
$title = $row['catname'];
do_html_url($url, $title);
echo '</li>';
}
echo '</ul></div>
<div id="right-col-container"><img src="images/GirlNoBag-right.jpg" class="girlimageclass" alt="" /></div>
<div id="main-content-container"><div id="content">
<div id="contentimages">
<ul>
<li class="itemimage"><a href="show_cat.php?catid=2"><img src="images/catalog/28061.gif" /><br />
<span class="caption">Bath &amp; Body</span></a></li>
<li class="itemimage"><a href="show_cat.php?catid=13"><img src="images/catalog/36755.gif" /><br />
For The Family</a></li>
<li class="itemimage"><a href="show_cat.php?catid=10"><img src="images/catalog/27019.gif" /><br />
Coastline</a></li>
<li class="itemimage"><a href="show_cat.php?catid=24"><img src="images/catalog/31298.gif" /><br />
Shabby Elegance</a></li>
<li class="itemimage"><a href="show_cat.php?catid=28"><img src="images/catalog/20679.gif" /><br />
<span class="caption"> World Inspirations</span></a></li>
<li class="itemimage"><a href="show_cat.php?catid=19"><img src="images/catalog/21923.gif" /><br />
Kitchen &amp; Entertaining</a></li>
<li class="itemimage"><a href="show_cat.php?catid=9"><img src="images/catalog/28209.gif" /><br />
Holiday</a></li>
<li class="itemimage"><a href="show_cat.php?catid=17"><img src="images/catalog/1932.gif" /><br />
Inspirational</a></li>
<li class="itemimage"><a href="show_cat.php?catid=14"><img src="images/catalog/31027.gif" /><br />
<span class="caption">Fountains</span></a></li>
<li class="itemimage"><a href="show_cat.php?catid=7"><img src="images/catalog/27278.gif" /><br />
Candles</a></li>
<li class="itemimage"><a href="show_cat.php?catid=20"><img src="images/catalog/21780.gif" /><br />
Luminous Visions</a></li>
<li class="itemimage"><a href="show_cat.php?catid=18"><img src="images/catalog/3369.gif" /><br />
Just For Her</a></li>
<li class="itemimage"><a href="show_cat.php?catid=22"><img src="images/catalog/30742.gif" border="0" /><br />
<span class="caption">Myth &amp; Legend</span></a></li>
<li class="itemimage"><a href="show_cat.php?catid=4"><img src="images/catalog/20591.gif" border="0" /><br />
Beautiful Beasts</a></li>
<li class="itemimage"><a href="show_cat.php?catid=25"><img src="images/catalog/25023.gif" border="0" /><br />
Spirit of the West</a></li>
<li class="itemimage"><a href="show_cat.php?catid=1"><img src="images/catalog/29193.gif" border="0" /><br />
Americana</a></li>
<li class="itemimage"><a href="show_cat.php?catid=6"><img src="images/catalog/20100.gif" border="0" /><br />
<span class="caption"> Bulk Buys</span></a></li>
<li class="itemimage"><a href="show_cat.php?catid=23"><img src="images/catalog/25306.gif" border="0" /><br />
Outdoor Living</a></li>
<li class="itemimage"><a href="show_cat.php?catid=16"><img src="images/catalog/20302.gif" border="0" /><br />
Household Essentials</a></li>
<li class="itemimage"><a href="show_cat.php?catid=27"><img src="images/catalog/21943.gif" border="0" /><br />
Travel Essentials</a></li>
<li class="itemimage"><a href="show_cat.php?catid=15"><img src="images/catalog/31351.gif" border="0" /><br />
<span class="caption"> Fun For All</span></a></li>
<li class="itemimage"><a href="show_cat.php?catid=12"><img src="images/catalog/35269.gif" border="0" /><br />
For Pets</a></li>
</ul>
</div><div class="clearfix"></div>
';
}

function display_items($item_array)
{
//display all books in the array passed in
if (!is_array($item_array))
{
echo '<br />No items currently available in this category<br />';
}
else
{
//create table
echo '<div id="left-col-container"><ul><li class="listtitle">Categories</li>';
echo '<li>';
$url = 'show_cat.php?catid='.($row['catid']);
$title = $row['catname'];
do_html_url($url, $title);
echo '</li>';
echo '</ul></div>';
echo '<div id="right-col-container"><img src="images/GirlNoBag-right.jpg" class="girlimageclass" alt="" /></div>
<div id="main-content-container"><div id="content"><div id="contentimages"><ul>';

//create a table row for each book
foreach ($item_array as $row)
{
$url = 'show_book.php?itemno='.($row['itemno']);
echo '<li class="itemimage">';
if (@file_exists('images/catalog/'.$row['itemno'].'.gif'))
{
$title = '<img src=\'images/catalog/'.($row['itemno']).'.gif\' border=0 />';
do_html_url($url, $title);
}
else
{
echo '<br />';
}
$title = $row['title'].'<span class="caption">'.$row['shortdescription'].'</span>';
do_html_url($url, $title);
echo '</li>';
}
echo '</ul></div>';
}
echo '<div class="clearfix"></div>
<hr />';
}

function display_book_details($item)
{
// display all details about this book
if (is_array($item))
{
echo '<div id="right-col-container"><img src="images/GirlNoBag-right.jpg" class="girlimageclass" alt="" /></div>
<div id="main-content-container"><div id="content"><div id="contentimages"><ul>';
//display the picture if there is one
if (@file_exists('images/catalog/'.($item['itemno']).'.gif'))
{
$size = GetImageSize('images/catalog/'.$item['itemno'].'.gif');
if($size[0]>0 && $size[1]>0)
echo '<li class="itemimage"><img src=\'images/catalog/'.$item['itemno'].'.gif\' border=0 '.$size[3].'></li>';
}
echo '</ul></div><div id="itemdetail"><ul>';
echo '<li><b>Name:</b> '.$item['shortdescription'].'</li>';
echo '<li><b>Item No.:</b> '.$item['itemno'].'</li>';
echo '</li><li><b>Our Price:</b> ';
echo number_format($item['retailprice'], 2);
echo '</li><li><b>Description:</b> ';
echo $item['longdescription'];
echo '</li></ul></div>';
}
else
echo 'The details of this item cannot be displayed at this time.';
echo '<hr />';
}

function display_checkout_form()
{
//display the form that asks for name and address
?>
<br />
<table border = 0 width = '100%' cellspacing = 0>
<form action = 'purchase.php' method = 'post'>
<tr><th colspan = 2 bgcolor='#cccccc'>Your Details</th></tr>
<tr>
<td>First Name</td>
<td><input type = 'text' name = 'customerfirstname' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type = 'text' name = 'customerlastname' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Address</td>
<td><input type = 'text' name = 'address' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type = 'text' name = 'city' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type = 'text' name = 'state' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type = 'text' name = 'zip' value = "" maxlength = 10 size = 40></td>
</tr>
<tr><th colspan = 2 bgcolor='#cccccc'>Shipping Address (leave blank if as above)</th></tr>
<tr>
<td>Name</td>
<td><input type = 'text' name = 'ship_name' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>Address</td>
<td><input type = 'text' name = 'ship_address' value = "" maxlength = 40 size = 40></td>
</tr>
<tr>
<td>City/Suburb</td>
<td><input type = 'text' name = 'ship_city' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>State/Province</td>
<td><input type = 'text' name = 'ship_state' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td>Postal Code or Zip Code</td>
<td><input type = 'text' name = 'ship_zip' value = "" maxlength = 10 size = 40></td>
</tr>
<tr>
<td>Country</td>
<td><input type = 'text' name = 'ship_country' value = "" maxlength = 20 size = 40></td>
</tr>
<tr>
<td colspan = 2 align = 'center'>
<b>Please press Purchase to confirm your purchase,
or Continue Shopping to add or remove items</b>
<?php display_form_button('purchase', 'Purchase These Items'); ?>
</td>
</tr>
</form>
</table><hr />
<?php
}

function display_shipping($shipping)
{
// display table row with shipping cost and total price including 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 INCLUDING SHIPPING</th>
<th bgcolor='#cccccc' align = 'right'>$<?php echo number_format($shipping+$_SESSION['total_price'], 2); ?></th>
</tr>
</table><br />
<?php
}

function display_card_form($name)
{
//display form asking for credit card details
?>
<table border = 0 width = '100%' cellspacing = 0>
<form action = 'process.php' method = 'post'>
<tr><th colspan = 2 bgcolor="#cccccc">Credit Card Details</th></tr>
<tr>
<td>Type</td>
<td><select name = 'card_type'><option>VISA<option>MasterCard<option>American Express</select></td>
</tr>
<tr>
<td>Number</td>
<td><input type = 'text' name = 'card_number' value = "" maxlength = 16 size = 40></td>
</tr>
<tr>
<td>AMEX code (if required)</td>
<td><input type = 'text' name = 'amex_code' value = "" maxlength = 4 size = 4></td>
</tr>
<tr>
<td>Expiry Date</td>
<td>Month <select name = 'card_month'><option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10<option>11<option>12</select>
Year <select name = 'card_year'><option>00<option>01<option>02<option>03<option>04<option>05<option>06<option>07<option>08<option>09<option>10</select></td>
</tr>
<tr>
<td>Name on Card</td>
<td><input type = 'text' name = 'card_name' value = "<?php echo $name; ?>" maxlength = 40 size = 40></td>
</tr>
<tr>
<td colspan = 2 align = 'center'>
<b>Please press Purchase to confirm your purchase,
or Continue Shopping to add or remove items</b>
<?php display_form_button('purchase', 'Purchase These Items'); ?>
</td>
</tr>
</table>
<?php
}



function display_cart($cart, $change = true, $images = 1)
{
// 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><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 $itemno => $qty)
{
$item = get_book_details($itemno);
echo '<tr>';
if($images ==true)
{
echo '<td align = left>';
if (file_exists("images/catalog/$itemno.gif"))
{
$size = GetImageSize('images/catalog'.$itemno.'.gif');
if($size[0]>0 && $size[1]>0)
{
echo '<img src="images/catalog/'.$itemno.'.gif" border=0 ';
echo 'width = '. $size[0]/3 .' height = ' .$size[1]/3 . ' />';
}
}
else
echo '&nbsp;';
echo '</td>';
}
echo '<td align = "left">';
echo '<a href = "show_book.php?itemno='.$itemno.'">'.$item['shortdescription'].'</a>';
echo '</td><td align = "center">$'.number_format($item['retailprice'], 2);
echo '</td><td align = "center">';
// if we allow changes, quantities are in text boxes
if ($change == true)
echo "<input type = 'text' name = \"$itemno\" value = \"$qty\" size = 3>";
else
echo $qty;
echo '</td><td align = "center">$'.number_format($item['retailprice']*$qty,2)."</td></tr>\n";
}
// display total row
echo "<tr>
<th colspan = ". (2+$images) ." bgcolor=\"#cccccc\">&nbsp;</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) .'>&nbsp;</td>
<td align = "center">
<input type = "hidden" name = "save" value = true>
<input type = "image" src = "images/save-changes.gif"
border = 0 alt = "Save Changes">
</td>
<td>&nbsp;</td>
</tr>';
}
echo '</form></table>';
}

function display_login_form()
{
// dispaly form asking for name and password
?>
<form method='post' action="admin.php">
<table bgcolor='#cccccc'>
<tr>
<td>Username:</td>
<td><input type='text' name='username'></td></tr>
<tr>
<td>Password:</td>
<td><input type='password' name='passwd'></td></tr>
<tr>
<td colspan=2 align='center'>
<input type='submit' value="Log in"></td></tr>
<tr>
</table></form>
<?php
}

function display_admin_menu()
{
?>
<br />
<a href="index.php">Go to main site</a><br />
<a href="insert_category_form.php">Add a new category</a><br />
<a href="insert_book_form.php">Add a new book</a><br />
<a href="change_password_form.php">Change admin password</a><br />
<?php

}

function display_button($target, $image, $alt)
{
echo "<center><a href=\"$target\"><img src=\"images/$image".".gif\"
alt=\"$alt\" border=0 height = 50 width = 135></a></center>";
}

function display_form_button($image, $alt)
{
echo "<center><input type = image src=\"images/$image".".gif\"
alt=\"$alt\" border=0 height = 50 width = 135></center>";
}

?>


function display_items($item_array) is the function that lists the items in the category

now if you dare tell me that I'm missing something easy I swear I'll beat you silly :)

Brandoe85
09-05-2006, 01:50 AM
Looks like it should be in this file: book_sc_fns.php. Can you check there?

harlequin2k5
09-05-2006, 02:13 AM
contents of book_sc_fns.php

<?php

include_once('db_fns.php');
include_once('data_valid_fns.php');
include_once('output_fns.php');
include_once('book_fns.php');
include_once('user_auth_fns.php');
include_once('admin_fns.php');
include_once('order_fns.php');

?>


and this is book_fns.php

<?php
function calculate_shipping_cost()
{
// as we are shipping products all over the world
// via teleportation, shipping is fixed
return 20.00;
}

function get_categories()
{
// query database for a list of categories
$conn = db_connect();
$query = 'select catid, catname
from tblCategories';
$result = @$conn->query($query);
if (!$result)
return false;
$num_cats = @$result->num_rows;
if ($num_cats ==0)
return false;
$result = db_result_to_array($result);
return $result;
}

function get_category_name($catid)
{
// query database for the name for a category id
$conn = db_connect();
$query = "select catname
from tblCategories
where catid = $catid";
$result = @$conn->query($query);
if (!$result)
return false;
$num_cats = @$result->num_rows;
if ($num_cats ==0)
return false;
$row = $result->fetch_object();
return $row->catname;
}


function get_items($catid)
{
// query database for the books in a category
if (!$catid || $catid=='')
return false;

$conn = db_connect();
$query = "select * from tblProducts where catid='$catid'";
$result = @$conn->query($query);
if (!$result)
return false;
$num_books = @$result->num_rows;
if ($num_books ==0)
return false;
$result = db_result_to_array($result);
return $result;
}

function get_book_details($itemno)
{
// query database for all details for a particular book
if (!$itemno || $itemno=='')
return false;

$conn = db_connect();
$query = "select * from tblProducts where itemno='$itemno'";
$result = @$conn->query($query);
if (!$result)
return false;
$result = @$result->fetch_assoc();
return $result;
}

function calculate_price($cart)
{
// sum total price for all items in shopping cart
$price = 0.0;
if(is_array($cart))
{
$conn = db_connect();
foreach($cart as $isbn => $qty)
{
$query = "select retailprice from tblProducts where itemno='$itemno'";
$result = $conn->query($query);
if ($result)
{
$item = $result->fetch_object();
$item_price = $item->price;
$price +=$item_price*$qty;
}
}
}
return $price;
}

function calculate_items($cart)
{
// sum total items in shopping cart
$items = 0;
if(is_array($cart))
{
foreach($cart as $itemno => $qty)
{
$items += $qty;
}
}
return $items;
}

?>

Brandoe85
09-05-2006, 03:46 PM
Ok, that helps. My assumption stays the same. :)

Add $cat_array = get_categories();
then
display_categories($cat_array);

If you look at get_categories() it's fetching some category info, then if you look in display_categories() it's spitting it out the rows from get_categories().