PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 11th, 2004, 02:52 PM
aloo aloo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 26 aloo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
showcart.php

Hi all,

I'm trying to get the shoppingcart from the tutorial on this site to work.
I've modified it a bit, and now I'm stuck.

i cant get the showcart.php to work it just gives a blank page.
below is the code

showcart.php

<?
function ShowCart()
{
$result = mysql_query("select * from cart inner join products on cart.item_id = products.item_id where cart.cookie_id = '" . GetCartId() . "' order by products.item_name asc")
or mysql_error($result);

// once we've retrieved the list, each item is displayed as part of a table, as a table row
echo "<table border='1' cellspacing='0' cellpadding='2' class='cart'>";

$color1 = "gray";
$color2 = "lightgray";
$row_count = 0;
while($row = mysql_fetch_array($result))
{
// increment the total cost of all items
$totalCost += ($row["qty"] * $row["item_price"]);

// alternating table colors
$row_color = ($row_count % 2) ? $color1: $color2;
?>
<tr><td bgcolor="<?php echo $row_color;?>">
<font face='verdana' size='1' color='black'>
<select name='<?php echo $row['item_id'];?>' onChange='UpdateQty(this)'

<?php
for ($i = 1; $i <= 20; $i++)
{
echo "<option ";
if ($row["qty"] == $i)
{
echo " SELECTED ";
}

echo ">" . $i . "</option>";
}
?>
</select></font></td>
<td width="60%" height="25" bgcolor="<?php echo $row_color;?>">
<font style="color:#FFFFFF;font-size:12pt;font-weight:bold;" face="verdana,arial,helvetica,sans-serif" size='1' color='black'>
<?php echo $row["item_name"];?> </font></td>
<td width="20%" height="25" bgcolor="<?php echo $row_color;?>">
<font style="font-size:12pt;font-weight:bold;" face='verdana' size='1' color='white'>$
<?php echo number_format($row['item_price'], 2, '.', ',');?></font> </td>
<td width="10%" height="25" bgcolor="<?php echo $row_color;?>">
<font face='verdana' size='1' color='black'>
<a href=cart.php?action=remove_item&id=<?php echo $row['item_id'];?>>Remove</a>
</font></td> </tr>
<?php

// increase row count by 1
$row_count++;

}
?>

<tr><td width='100%' colspan='4'>
<hr size='1' color='red' NOSHADE>
</td></tr>
<tr><td width='70%' colspan='2'>
<font face='verdana' size='1' color='black'>
<a href='products.php'><< Keep Shopping</a>
</font></td>
<td width='30%' colspan='2'>
<font face='verdana' size='2' color='black'>
<b>Total: <?php echo number_format($totalCost, 2, ".", ",");?> </b>
</font></td></tr>
</table>
<?php
}

thanks

Reply With Quote
  #2  
Old January 11th, 2004, 06:56 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
for future reference, put [ php][/php ] blocks around the PHP code and the forum will color-ize your code...

i don't know if its the way you posted it, but you're missing a ?> at the end of your code...

Quote:
PHP Code:
<? 
function ShowCart() 

$result mysql_query("select * from cart inner join products on cart.item_id = products.item_id where cart.cookie_id = '" GetCartId() . "' order by products.item_name asc"
or 
mysql_error($result); 

// once we've retrieved the list, each item is displayed as part of a table, as a table row 
echo "<table border='1' cellspacing='0' cellpadding='2' class='cart'>"

$color1 "gray"
$color2 "lightgray"
$row_count 0
while(
$row mysql_fetch_array($result)) 

// increment the total cost of all items 
$totalCost += ($row["qty"] * $row["item_price"]); 

// alternating table colors 
$row_color = ($row_count 2) ? $color1$color2
?> 
<tr><td bgcolor="<?php echo $row_color;?>"> 
<font face='verdana' size='1' color='black'> 
<select name='<?php echo $row['item_id'];?>' onChange='UpdateQty(this)' 

<?php 
for ($i 1$i <= 20$i++) 

echo 
"<option "
if (
$row["qty"] == $i

echo 
" SELECTED "


echo 
">" $i "</option>"

?> 
</select></font></td> 
<td width="60%" height="25" bgcolor="<?php echo $row_color;?>"> 
<font style="color:#FFFFFF;font-size:12pt;font-weight:bold;" face="verdana,arial,helvetica,sans-serif" size='1' color='black'> 
<?php echo $row["item_name"];?> </font></td> 
<td width="20%" height="25" bgcolor="<?php echo $row_color;?>"> 
<font style="font-size:12pt;font-weight:bold;" face='verdana' size='1' color='white'>$ 
<?php echo number_format($row['item_price'], 2'.'',');?></font> </td> 
<td width="10%" height="25" bgcolor="<?php echo $row_color;?>"> 
<font face='verdana' size='1' color='black'> 
<a href=cart.php?action=remove_item&id=<?php echo $row['item_id'];?>>Remove</a> 
</font></td> </tr> 
<?php 

// increase row count by 1 
$row_count++; 


?> 

<tr><td width='100%' colspan='4'> 
<hr size='1' color='red' NOSHADE> 
</td></tr> 
<tr><td width='70%' colspan='2'> 
<font face='verdana' size='1' color='black'> 
<a href='products.php'><< Keep Shopping</a> 
</font></td> 
<td width='30%' colspan='2'> 
<font face='verdana' size='2' color='black'> 
<b>Total: <?php echo number_format($totalCost2"."",");?> </b> 
</font></td></tr> 
</table> 
<?php 
}



Additionally, I can't really tell from the indenting, but is the entire script declared as a function?
In which case, it may help to call the function at the end...

Reply With Quote
  #3  
Old January 12th, 2004, 03:29 AM
aloo aloo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 26 aloo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
im new to php some not used to the indenting

showcart.php only has one function

thanks

Reply With Quote
  #4  
Old January 12th, 2004, 08:59 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
is it being called?

perhaps you're missing ShowCart() somewhere?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > showcart.php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT