In php, mysql how to run a loop only if record exist -


I have a php script that contains the user's selection / calculated based on input and range of form Rilods, I run them If no record is done in additional table and not on farm reload, then a loop will be run with this status.

My partial php script bills - detail.php: This hope seeks Sufi:

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Cash Bill Details & 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) {dead ('Could not connect:' Mysql_error ()); } Mysql_select_db ("svga", $ con); $ User = $ _SESSION ['user']; // & lt ;! -------------- Validities ------------------- & gt; Echo "& lt; form name = 'form1' & gt;"; Echo "ECR: input type = 'text' size = '10 'maximum length =' 10 'name =' ECRN 'onchange = \" showcase (this.value); \ "& Gt; & lt; br & gt;"; "Product type" echo; 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 = 'other' & gt; other & lt; / options & gt;"; Echo "& lt; / select & gt;"; Echo ""; // --- according to the value per copy value per user --------------------- $ 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']; // - Bill header table from the user as input to find the details of the bill details ------ $ recs = mysql_query ( "SELECT * FROM BILLDTLS WHERE AC_code = '$ cust_code' and Prod_desc = '$ product'"); While ($ rec2 = mysql_fetch_assoc ($ rec)) {mysql_query ( "insert DEMURAGE (DC_No, DC_date, Ac_code, Product_Desc) VALUES ( '$ rec2 [DC]', '$ rec2 [dcdate]', '$ rec2 [accode ] ',' $ rec2 [product] ' ");}} mysql_close ($ con) ;? & gt;   

You can add a Boolean variable loop before you can use it to track a record that has already been added. The following code is going to be largely conceived that you have not done so. ($ NUM_ROWS & gt; 0 & amp; amp; amp; amp; amp; & amp; amp; amp; amp; $ recordAdded The Od provided an example of themselves, but hopefully you get the idea to

  set at $ recordAdded = false // false start == FALSE) {// Code // Set True to execute after the initial successful execution $ recordAdded = to the TRUE value;}    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -