flemingmike Posted June 17, 2015 Share Posted June 17, 2015 hi, I have a script that displays a signature of a signed work order. here is the file that calls all the work orders <style> @page { size 8.5in 11in; } div.page { page-break-after: always } </style> <?php include 'config.php'; $id = $_GET['id']; $result7 = mysql_query("SELECT * FROM workorders WHERE jobnumber = '$id'"); while($row7 = mysql_fetch_array($result7)) { $woid = $row7['id']; ?> <div class="page"> <?php include "printworkorder.php"; ?> </div> <?php } ?> then in the printworkorder.php file (which works fine with only one instance of loading it) when loading multiple work orders to print, it only signs the document on the last one. any idea how I can get it to sign all instances? <?php include 'config.php'; if(isset($woid)){ } else { $woid = $_GET['id']; } $result = mysql_query("SELECT * FROM workorders WHERE id = $woid"); while($row = mysql_fetch_array($result)) { $wodate = $row['date']; $wojobnum = $row['jobnumber']; $timesheetid = $row['timesheetid']; $start = $row['start']; $finish = $row['finish']; $timebilled = $row['timebilled']; $description = $row['description']; $signator = $row['signator']; $signature = $row['signature']; $sig_hash = $row['sig_hash']; $created = $row['created']; } $result3 = mysql_query("SELECT * FROM timesheet WHERE id = '$timesheetid'"); $talltime = 0; while($row3 = mysql_fetch_array($result3)) { $tid=$row3['id']; $tdate=$row3['date']; $tjobnumber=$row3['jobnumber']; $teid=$row3['eid']; $tdescription=$row3['description']; $tsignin=$row3['start']; $tfinish=$row3['finish']; $tlunch=$row3['lunch']; $tschednum=$row3['schednum']; $shortid=substr($tjobnumber, 5, -1); //remove the first 5 characters and minus the last character $jobid=substr($tjobnumber, 5); //remove the first 5 characters $result = mysql_query("SELECT * FROM jobs WHERE id = '$shortid'"); while($row = mysql_fetch_array($result)) { $jstatus=$row['status']; $jaddress=$row['address']; } $mechanic = mysql_query("SELECT * FROM staff WHERE eid = '$teid'"); while($row4 = mysql_fetch_array($mechanic)) { $tmechanic=$row4['name']; } } $result9 = mysql_query("SELECT * FROM jobs WHERE id = '$shortid'"); while($row9 = mysql_fetch_array($result9)) { $tcustomer=$row9['customer']; } ?> <table border="0" cellpadding="0" style="border-collapse: collapse" width="100%"> <tr><td> </td></tr> <tr><td> </td></tr> <tr> <td valign="bottom"><div align="center"> <table border="0" cellpadding="2" style="border-collapse: collapse" width="100%" bordercolorlight="#000000" bordercolordark="#000000"> <tr> <td><font face="Calibri" style="font-size: (11 pt)"> <img border="0" src="images/logo.png" ></font></td> <td width="237" valign="top"> <p align="center"> <font face="Calibri" style="font-size: (11 pt)"> <font size="6">Work Order</font><br><?php echo $woid ?></font></td> </tr> </table> </div> </td> </tr> <tr> <td valign="bottom"> </td> </tr> <tr> <td valign="top"> <font face="Calibri" style="font-size: (11 pt)"> <br> </font> <div align="center"> <table border="0" cellpadding="2" style="border-collapse: collapse" width="90%" bordercolorlight="#000000" bordercolordark="#000000"> <tr> <td width="7%"> <i> <font face="Calibri" style="font-size: (11 pt); font-weight:700">Customer:</font></i></td> <td style="border-top-style: none; border-top-width: medium" rowspan="6" valign="top" width="93%"><?php echo $tcustomer; ?></td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td> </td> </tr> <tr> <td colspan="2"> <div align="center"> <table border="1" cellpadding="2" style="border-collapse: collapse" width="100%" bordercolorlight="#000000" bordercolordark="#000000"> <tr> <td align="center" valign="top"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> JOB NUMBER</font></i><br><?php echo "$jobid"; ?></td> <td align="center" valign="top"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> DATE</font></i><br><?php echo date('F j, Y', $created); ?></td> <td align="center" valign="top" colspan="2"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> ADDRESS</font></i><br><?php echo "$jaddress"; ?></td> </tr> <tr> <td colspan="4" ></td> </tr> <tr> <td align="center" valign="top"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> TECHNICIAN</font></i><br><?php echo "$tmechanic"; ?></td> <td align="center" valign="top"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> TIME IN</font></i><br><?php echo "$start"; ?></td> <td align="center" valign="top"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> TIME OUT</font></i><br><?php echo "$finish"; ?></td> <td align="center" valign="top"><i> <font style="font-size: (11 pt); font-weight: 700" face="Calibri"> TIME BILLED</font></i><br><?php echo "$timebilled hours"; ?></td> </tr> <tr> <td colspan="4"> <font face="Calibri" style="font-size: (11 pt)"> <i><b>Description Of Work: </b></i></font> <br> <tt><font face="Arial"><?php echo $description; ?></font><br><br> </td> </tr> </table> </div> </td> </tr> </table> </div> </td> </tr> <tr> <td valign="bottom"> <div align="center"> <table border="0" cellpadding="2" style="border-collapse: collapse" width="90%" bordercolorlight="#000000" bordercolordark="#000000"> <tr> <td style="border-top-style: none; border-top-width: medium"> </td> <td width="175" style="border-top-style: none; border-top-width: medium"> </td> </tr> <tr> <td> <br><br><br> Date Signed: <?php echo date('F j, Y g:i A', $created); ?><br><br> Printed Name: <?php echo htmlentities($signator, ENT_NOQUOTES, 'UTF-8'); ?><br><br> Signature: <?php //regenerate signature ?> <div class="sigPad signed"> <div class="sigWrapper"> <div class="typed"> <?php echo htmlentities($signator, ENT_NOQUOTES, 'UTF-8'); ?> </div> <canvas class="pad" width="348" height="120"></canvas> </div> <br> </div> <script src="mobile/signature-pad/build/jquery.min.js"></script> <script src="mobile/signature-pad/build/jquery.signaturepad.min.js"></script> <script> $(document).ready(function () { // Write out the complete signature from the database to Javascript var sig = <?php echo $signature; ?>; $('.sigPad').signaturePad({displayOnly : true}).regenerate(sig); }); </script> <?php //regenerate signature ?> <br><br> </td> </tr> </table> </div> </td> </tr> <tr> <td valign="bottom"> <div align="center"> <div align="center"> <table border="0" cellpadding="2" style="border-collapse: collapse" width="90%" bordercolorlight="#000000" bordercolordark="#000000"> <tr> <td width="33%"> <font face="Calibri" style="font-size: (11 pt)" size="2">Phone: 905-420-2043</font></td> <td width="33%"> <p align="center"> <font face="Calibri" style="font-size: (11 pt)" size="2">817 Brock Road, Unit #7<br>Pickering, Ontario, L1W 3L9</font></td> <td width="33%"> <p align="right"> <font face="Calibri" style="font-size: (11 pt)" size="2">Fax: 905-420-5040</font> </td> </tr> </table> </div> </div> </td> </tr> </table> </div> any help is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/296881-include-file-only-loads-all-content-on-the-last-time-included/ Share on other sites More sharing options...
mac_gyver Posted June 18, 2015 Share Posted June 18, 2015 (edited) this is some confusing code and probably doesn't work because the output being produced is not valid. the markup you are producing, particularly the javascript, is being repeated for each main row you are looping over. you need to separate the concerns/responsibilities in the code. the data retrieval logic should all be together, come before any markup, not contain any html/javascript/css markup, and just store the retrieved data in a php array. the code building the page, starting with the <!DOCTYPE ... tag, should just take the data from the data retrieval logic and loop over it as needed to build the sections/views on the page. the things that only exist ONCE in the markup, such as the jquery javascript <script> ...</script> tags, should not be inside of any loop. next, you should never run database queries inside of loops. the data you are retrieving is related, as in the R in RDBMS. the correct way of retrieving related data is to run one query that JOINs the tables to retrieve all the related information at once. and here's the most confusing part from your code (we only see what you post, so it must clearly tell us the story of what you are doing), you are looping over the result from each of the queries, but i suspect that each query, except for the main one, only matches one row? OR can there be multiple timesheets per workorder, based on what appears to be a variable for totaling the time? you should also be using css instead of inline styling and the msyql_ database functions are obsolete and will be removed from php in the not to distant future. you should be switching to either the msyqli_ or PDO database library of functions (having all your database retrieval logic together, on in your case, where you should only have one query, will make switching to a different set of database functions easier.) in short - run one query that gets the data you want, retrieve and store that data into an array, then, in the code that's producing the page, loop over the data, building the markup needed to display that data. this will reduce all your code, make it easier to debug each concern/responsibility (which makes it easier for us to produce test data if we need to run your code to help with it), and make it clearer to us what you are doing. Edited June 18, 2015 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/296881-include-file-only-loads-all-content-on-the-last-time-included/#findComment-1514217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.