|
|
|
select ข้อมูลจากฐานข้อมูลแล้วใช้ checkbox เพื่อเลือกส่งค่าไปอีก from ทำยังไงครับบอกที |
|
|
|
|
|
|
|
ไหน Code ครับ
|
|
|
|
|
Date :
2011-09-16 21:37:19 |
By :
adaaugusta |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code ครับ
Sale.php
Code (PHP)
<html>
<head><title>000</title></head>
<body>
<td width="18000" align="left" valign="top">
<form action="checktest.php" name="from1" method="$_GET">
<p><span class="lopp"><strong>Please select product</strong></span>
<?
$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
$objDB = mysql_select_db("db_medicine");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$strSQL = "SELECT * FROM product";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<br>
</p>
<table width="946" border="1">
<tr class="vbvb">
<th width="36"> <div align="center">Select</div></th>
<th width="20"> <div align="center">ID </div></th>
<th width="354"> <div align="center">Name </div></th>
<th width="39"> <div align="center">Price </div></th>
<th width="39"> <div align="center">Unit </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td align="center"><input type="checkbox" name="TT[]" id="chkproduct" value="<?=$objResult["id"];?>"
<label for="TT"></label></td>
<td align="center"><?=$objResult["id"];?></td>
<td align="left" valign="top"><?=$objResult["name"];?></td>
<td align="center"><?=$objResult["price"];?></td>
<td align="center"><?=$objResult["number"];?></td>
</tr>
<?
}
?>
</table> <br>
<input type="submit" id="submit" value="submit" name="submit"
style="float:center;background:#3B59A8;
border:1px solid #000;color:#ffffff;font-weight:bold;"/>
</p>
<?
mysql_close($objConnect);
?>
</form></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
</body>
<script type="text/javascript">
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>
checktest.php
Code (PHP)
<htm><head><title>01</title></head>
<td width="945" align="left" valign="top"><form action="complete edit product.php" name="from2" method="post">
<table width="948" border="1">
</table>
<?php
$arr = array("$objResult[id]","$objResult[name]");
foreach ($arr as $value) {
echo "Value: $value<br>";
}
echo "<hr>";
reset($arr);
while(list($key, $value) = each($arr)) {
echo "Key: $key; Value: $value<br>";
}
echo "<hr>";
foreach($arr as $key => $value) {
echo "Key: $key; Value: $value<br>";
}
?>
<?
$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
$objDB = mysql_select_db("db_medicine");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
$strSQL = "SELECT * FROM product WHERE id = '".$_GET["TT"]."' ";
$objQuery = mysql_query($strSQL);
?>
<table width="827" border="1">
<tr class="สีเขียว">
<th width="175" align="left" valign="top"> <div align="center">Name </div></th>
<th width="70" align="center" valign="top"> <div align="center">Number </div></th>
<th width="82" align="center" valign="top"> <div align="center">Price </div></th>
</tr>
<tr>
<td width="35" align="center" valign="top"><div align="center">
<?=$objResult["name"];?></div></td>
<td width="175" align="left" valign="top">
<?=$objResult["number"];?></td>
<td width="238" align="left" valign="top">
<?=$objResult["price"];?></td>
</tr>
</table>
<p>
<input type="submit" value="Submit" name="submit2"
style="float:center;background:#3B59A8;
border:1px solid #000;color:#ffffff;font-weight:bold;"/>
<?
mysql_close($objConnect);
?>
</p>
<p><?
for($i=0;$i<count($_GET["TT"]);$i++)
{
if(trim($_GET["TT"][$i]) != "")
{
echo $_GET["TT"][$i]."<br>";
}
}
?> </p>
</form></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<script type="text/javascript">
var MenuBar2 = new Spry.Widget.MenuBar("MenuBar2", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
</script>
</body>
</html>
ในภาพที่2 จะเห็นว่ามี3อัน ที่จิงผมจะเรียกให้ข้อมูลมาปรากฏในตาราง แต่มีคนบอกว่ามันเป็น array ต้องเอาเข้า each ก่อนผมเลยลองเขียนแล้ว echo ออกมา มันออกมาเป็นคำว่า array หมดเลยครับแทนที่มันจะออกมาเป็นตัวเลข ส่วนอันที่3ที่เป็นตัวเลข ผมลองecho ตัวแปรออกมาเฉยๆมันดันได้แต่ไม่สามารถนำมาเรียกจากฐานข้อมูลได้ T-T
|
|
|
|
|
Date :
2011-09-17 10:59:39 |
By :
ronnachach |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (form.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<script language="JavaScript">
function onSave()
{
if(confirm('Do you want to save ?')==true)
{
return true;
}
else
{
return false;
}
}
</script>
<form name="frmMain" action="save.php" method="post" OnSubmit="return onSave();">
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
<th width="30"> <div align="center">Select </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center"><?=$objResult["CustomerID"];?></div></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><div align="center"><?=$objResult["CountryCode"];?></div></td>
<td align="right"><?=$objResult["Budget"];?></td>
<td align="right"><?=$objResult["Used"];?></td>
<td align="center"><input type="checkbox" name="chkEmail[]" value="<?=$objResult["Email"];?>"></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
<input type="submit" name="btnSave" value="Save">
</form>
</body>
</html>
Code (save.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
for($i=0;$i<count($_POST["chkEmail"]);$i++)
{
if($_POST["chkEmail"][$i] != "")
{
$strSQL = "INSERT INTO table_name (Mail) VALUES ('".$_POST["chkEmail"][$i]."')";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
}
}
echo "Record Insert.";
mysql_close($objConnect);
?>
</body>
</html>
Go to : PHP Multiple Checkbox
|
|
|
|
|
Date :
2011-09-18 17:20:16 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|