我有一个 php 脚本,它具有基于用户选择/输入的一系列计算和 FORM RELOADS,只有在表中而不是在 FORM RELOADS 上完成记录添加时,我才需要运行这些,如何在这种情况下运行循环。
我的部分 php 脚本 bill-detail.php: 希望这足够:
<html>
<head>
<title>Cash Bill Detail</title>
<script language="javascript">
function reload(form)
{
document.location.href = 'bill-detail.php'
}
function showecr(str)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","billecr.php?q1=" + str,false);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
$con = mysql_connect("localhost","svga","a!@#");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("svga", $con);
$user = $_SESSION['user'];
//<!--------------VALIDATIONS ------------------->
echo "<form name='form1'>";
echo "ECR: <input type='text' size='10' maxlength='10' name='ecrn' onchange=\"showecr(this.value);\"><br>";
echo "Product Type";
echo "<select name='product' onchange=\"reload(this.form);\">>";
echo "<option value='Gas'>Gas</option>";
echo "<option value='Others'>Others</option>";
echo "</select>";
echo "</form>";
//---As per user inputs copying value to variables---------------------
$hdr=mysql_query("SELECT * FROM BILLHDR_draft WHERE usr='$user'");
$hdr2=mysql_fetch_assoc($hdr);
$numrows=mysql_num_rows($hdr);
if ($numrows>0)
{
$cust_code=$hdr2['Ac_code'];
$product=$hdr2['prod_desc'];
//--Searching BILL DETAILS TABLE as per the user inputs from BILL HEADER Table------
$recs=mysql_query("SELECT * FROM BILLDTLS WHERE Ac_code='$cust_code' AND Prod_desc='$product'");
while ($rec2=mysql_fetch_assoc($recs))
{
mysql_query("INSERT INTO DEMURAGE (DC_No, DC_date, Ac_code, Product_Desc) VALUES ('$rec2[dc]', '$rec2[dcdate]', '$rec2[accode]', '$rec2[product]'");
}
}
mysql_close($con);
?>