question about product comparsion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Winter
Forum Newbie
Posts: 15
Joined: Fri Feb 07, 2003 12:29 pm
Location: Texas
Contact:

question about product comparsion

Post by Winter »

Hello,

I am doing a product comparison. The product list is generated dynamically from database. Each product listed on the product list has a checkbox, which can be checked for comparing. However, the product id that is checked cannot be passed to next page. Would you please tell me how do I get the product id from the product list page????
many thanks. :oops:

Here are the codes:

Product list page---------------------------------------------------

<form action="product_compare.php" method="POST">

<?php
include "../conn.inc";
$sql="select id, product_model_type, product_name, data_rate from product ";

$result=mysql_query($sql);
$row=mysql_num_rows($result);

echo "<table>";
while ($query_data=mysql_fetch_array($result))
{
$id=$query_data['id'];
$product_name=$query_data['product_name'];
$i=1;
echo "<tr><td><input type='checkbox' name='ID$i' value='$id'></td><td><a href='product_list.php?id=$id' target=_blank><font face='Arial' size=2>$product_name</font></a></td><tr>";
$i=$i+1;

}

echo "<tr><td colspan=6 align=right><font face='Arial' size=2><b>Total item(s):$row</font>";
echo "</table>";
echo "<input type='hidden' name='row' value='$row'>";
?>

<p><input type="submit" value="comparison " name="comparison ">
</form>



Product comparsion page---------------------------------------------------

.....
$row=(isset($_POST['row']))?$_POST['row']:chr(0);
for ($i=1;$i<=$row;$i++){
$id[$i]=(isset($_POST['ID$i']))?$_POST['ID$i']:chr(0);
if(isset($_POST['ID$i'])){echo "id=$id[$i]";}
else{echo "nothing";}
}


Winter
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

The same way you sent $row
Post Reply