|
|
|
ตรวจสอบ Checkbox ด้วย for แล้วค่าไม่มาครับ คือผมทำ checkbox ไว้หลายอัน แล้วให้ตรวจสอบด้วย for แต่ค่าไม่มาครับ |
|
|
|
|
|
|
|
Code (PHP)
<?
$checkidbring = $_POST["checkidbring"];
echo "count = ".count($checkidbring)."<br>";
for($i=0; $i <count($checkidbring); $i++)
{
$number=$_POST["number".$checkidbring[$i]];echo"$number";
$_SESSION["number".$checkidbring[$i]] = $number;
//echo " $_SESSION[\"number\"".$chkcsmaterialID[$i]."] = $number";
echo "checkidbring $i = ".$checkidbring[$i]."<br>";
include "connect.php";
$result=mysql_db_query($dbname,$sql);
$sql="SELECT * FROM tb_bring WHERE idbring='$checkidbring[$i]'" ;
echo "$sql";
$temp =(int)$amount-(int)$number ;
$amountwant= $checkidbring[$i];
echo "$amountwant";
if($temp>=0)
{
$sql1 = "update tb_bring set amount='$temp' where idbring='$amountwant' ";
echo "$sql1<br>";
$result1 = mysql_query($sql1);
$sql2= "INSERT INTO tb_bringwant (checkidbring, amountwant)
VALUES('$idbring[$i]','$temp')";
echo "$sql2 <br>";
$result2 = mysql_query($sql2);
}
}
session_register("checkidbring");
?>
ตย.
Code (PHP)
<?php if (empty($_POST)){ ?>
<form id="form1" name="form1" method="post" action="">
<p>
<input name="chk[]" type="checkbox" id="chk[]" value="1" />
1</p>
<p>
<input name="chk[]" type="checkbox" id="chk[]" value="2" />
2</p>
<p>
<input name="chk[]" type="checkbox" id="chk[]" value="3" />
3</p>
<p>
<input name="chk[]" type="checkbox" id="chk[]" value="4" />
4</p>
<p>
<input name="chk[]" type="checkbox" id="chk[]" value="5" />
5
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
<?php } else { ?>
<?php
$txt = $_POST['chk'];
for($i = 0; $i<count($txt); $i++):
echo $txt[$i];
endfor;
?>
<?php } ?>
|
|
|
|
|
Date :
2010-06-07 09:14:53 |
By :
ความรู้เท่าหางอึ่ง |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับสำหรับคำชี้แนะ จะลองทำความเข้าใจดูครับ
|
|
|
|
|
Date :
2010-06-07 10:23:44 |
By :
เตาะแตะ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|