Using Array with form submission

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry for all the dead space in my last post... I cleaned it up some here...
===========================================================================

I have been trying to get this to work and think I must be missing
something. I am using Kevin Yank's books and examples as a guide. Here is
what I have so far - this does work [as it should since Kevin created it..
8-) ]
 
I have a form that creates a list of items with a select link that when
clicked adds the selected item to a shopping cart. I would like to convert
this to a checkbox model. Here is what I have so far
=============================================
<?

/* Check User Script */

session_start(); // Start Session
if (!isset($_SESSION['cart']))
$_SESSION['cart'] = array();
if (isset($_GET['Select'])) {

// Add item to the end of the $_SESSION['cart'] array
$_SESSION['cart'][] = $_GET['Select'];
header('location: ' . $_SERVER['PHP_SELF'] . '?' . SID);

exit();
}
 
include("connects to dB");

$Info = mysql_query("SELECT the data");

$rows = mysql_num_rows($Info);

$oldCat="";

// Will give you the number of rows returned from the SELECT statement
// echo("$rows");

for($i = 0; $i < $rows; $i++) {
$SRecord = mysql_fetch_array($Info, MYSQL_ASSOC);

$ItemID[] = htmlspecialchars($SRecord["ItemID"]);
$CatID[] = htmlspecialchars($SRecord["CatID"]);
$Category[] = htmlspecialchars($SRecord["ProdCategory"]);
$Model[] = htmlspecialchars($SRecord["ItemModel"]);
$Description[] = htmlspecialchars($SRecord["ItemDescription"]);
$Price[] = htmlspecialchars($SRecord["ItemPrice"]);

 {
IF ($oldCat != $Category[$i] )
{ 
echo("<table cellspacing=2 cellpadding=2 border=1 width=700>");
echo("<tr>");
echo("<tr></tr><center><font face=Arial
size=-1><b>Category:&nbsp;&nbsp;</b></font>");

echo("<font face=Arial size=-1><b>$Category[$i]</b></font></center></tr>");
$oldCat="$Category[$i]";
 
}

echo("</tr>");
}

?> 
<tr> 
<Td><font face="Arial" size="-1">

<? echo('<td><a href="' . $_SERVER['PHP_SELF'] .'?Select=' . $i .
'">Select</a></td>');?> //Change this out to a checkbox

<Td><font face="Arial" size="-1"><? echo ("$CatID[$i]"); ?></FONT></A></td>
<td><font face="Arial" size="-1"><? echo("$Model[$i]"); ?></font></td>
<td><font face="Arial" size="-1"><? echo("$Description[$i]"); ?></font></td>
<td><font face="Arial" size="-1">$<? echo (number_format("$Price[$i],2"));
?></font></td>

<?
}
?>
============================================================================

I want to change the Select statement above to

<? echo ("<input type='checkbox' name='select[]' value='$ItemID[$i]'>" .
"$ItemID[$i]"); ?></FONT></A></td>

but can't seem to make the addition to the cart work.....

Any idea how to change the Select to a check box and have it loop threw the
array so that each selected item is added to the shopping cart?? Once I have
The cart working I will be submitting the complete cart into a MySQL dB


Thanks in advance for all your help..

 

Aleks


 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux