Note that there are some explanatory texts on larger screens.

plurals
  1. POIn php, mysql how to run a loop only if record exist
    primarykey
    data
    text
    <p>I have a php script which has series of calculations and FORM RELOADS based on user Selection/Inputs, I need to run these only IF a record ADDITION is done to the table and not on FORM RELOADS, how to run a loop with this condition.</p> <p><strong>my PARTIAL php script bill-detail.php:</strong> HOPE THIS WOULD SUFFICE:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Cash Bill Detail&lt;/title&gt; &lt;script language="javascript"&gt; 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(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;?php $con = mysql_connect("localhost","svga","a!@#"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("svga", $con); $user = $_SESSION['user']; //&lt;!--------------VALIDATIONS -------------------&gt; echo "&lt;form name='form1'&gt;"; echo "ECR: &lt;input type='text' size='10' maxlength='10' name='ecrn' onchange=\"showecr(this.value);\"&gt;&lt;br&gt;"; echo "Product Type"; echo "&lt;select name='product' onchange=\"reload(this.form);\"&gt;&gt;"; echo "&lt;option value='Gas'&gt;Gas&lt;/option&gt;"; echo "&lt;option value='Others'&gt;Others&lt;/option&gt;"; echo "&lt;/select&gt;"; echo "&lt;/form&gt;"; //---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&gt;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); ?&gt; </code></pre> <p> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload