2003-11-17
153 HIT
|
단일상품 구매도 가능하고 다중 상품도 구매가 가능한 방법이 있어 소개합니다. 이미지 Submit 버튼을 이용하시면 여러개의 Submit 버튼이 있어도 어느것이 눌러졌는지 PHP 에서 알 수 있습니다. Submit 이름이 sub[0]~sub[9]라고 한다면 sub[0]_x 이렇게 확인하시면 될것 같습니다. /* index.php */ <? $pro_num = array(12,13,14,15,16,17,18,19,20,21); ?> <html> <head> <title>무제 문서</title> <meta http-equiv="Content-Type" content="text/html; charset=euc-kr"> </head> <body bgcolor="#FFFFFF" text="#000000"> <form name="form1" method="post" action="process.php"> <table width="400" border="0" cellspacing="0" cellpadding="2"> <? $pro_cnt = count($pro_num); for($i=0; $i<$pro_cnt; $i++) { ?> <tr> <td><?echo$i?></td> <td>상품설명<?echo$i?></td> <td width="120"> <input type="hidden" name="all_product[<?echo$i?>]" value="<?echo$pro_num[$i]?>"> <input type="checkbox" name="product[<?echo$i?>]" value="<?echo$pro_num[$i]?>"> <input type="image" border="0" name="sub[<?echo$i?>]" src="abc.gif" width="80" height="24"> </td> </tr> <? } ?> </table> </form> </body> </html> /* process.php */ <? $select_product = array(); for($i=0; $i<10; $i++) { if($product[$i] != Null) { $select_product[] = $product[$i]; } } for($i=0; $i<10; $i++) { if($sub[$i] != Null) { $select_submit = $all_product[$i]; } } if(!in_array($select_submit, $select_product) ) { $select_product[] = $select_submit; } $select_cnt = count($select_product); for($i=0; $i<$select_cnt; $i++) { echo "구매 상품 : $select_product[$i]<br>"; } ?> |

