|
|
|
การเพิ่มแถว 1.อยากได้โค้ดการเพิ่มแถวโดยใช้การกดปุ่มButton2.ถ้าเพิ่มแถวได้แล้ว |
|
|
|
|
|
|
|
Code (phpMySQLAddForm.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>
<form action="phpMySQLAddSave.php" name="frmAdd" method="post">
Select Line :
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<?
for($i=1;$i<=50;$i++)
{
if($_GET["Line"] == $i)
{
$sel = "selected";
}
else
{
$sel = "";
}
?>
<option value="<?=$_SERVER["PHP_SELF"];?>?Line=<?=$i;?>" <?=$sel;?>><?=$i;?></option>
<?
}
?>
</select>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <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="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<?
$line = $_GET["Line"];
if($line == 0){$line=1;}
for($i=1;$i<=$line;$i++)
{
?>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID<?=$i;?>" size="5"></div></td>
<td><input type="text" name="txtName<?=$i;?>" size="20"></td>
<td><input type="text" name="txtEmail<?=$i;?>" size="20"></td>
<td><div align="center"><input type="text" name="txtCountryCode<?=$i;?>" size="2"></div></td>
<td align="right"><input type="text" name="txtBudget<?=$i;?>" size="5"></td>
<td align="right"><input type="text" name="txtUsed<?=$i;?>" size="5"></td>
</tr>
<?
}
?>
</table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
</body>
</html>
Code (phpMySQLAddSave.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=1;$i<=$_POST["hdnLine"];$i++)
{
if($_POST["txtCustomerID$i"] != "")
{
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtCustomerID$i"]."','".$_POST["txtName$i"]."', ";
$strSQL .="'".$_POST["txtEmail$i"]."' ";
$strSQL .=",'".$_POST["txtCountryCode$i"]."','".$_POST["txtBudget$i"]."', ";
$strSQL .="'".$_POST["txtUsed$i"]."') ";
$objQuery = mysql_query($strSQL);
}
}
echo "Save Done. Click <a href='phpMySQLListRecord.php'>here</a> to view.";
mysql_close($objConnect);
?>
</body>
</html>
Code (phpMySQLListRecord.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");
$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>
</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>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
</body>
</html>
Screenshot
|
|
|
|
|
Date :
2009-11-09 14:04:36 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณนะค่ะ
|
|
|
|
|
Date :
2009-11-09 14:17:23 |
By :
หยก |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code ของพี่วิน พอเลือกแถวแล้ว มัน Refresh หน้าด้วยใช่ไหมครับ
|
|
|
|
|
Date :
2011-03-07 20:23:59 |
By :
หนุ่มช่างฝัน |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|