psuplat Posted July 15, 2010 Share Posted July 15, 2010 The code below maybe a bit crude, rude and confusing but it's just the work in progress, will tweak later. Anyway, back to issue. I'm creating a page that creates a report for daily audit. On main page user inputs the date he wants the report to be for, then he gets a report page. On report page I have the following queries running: 1. list audits for type cm 2. list specification checks for type cm 3. list audits for type ax 4. list specification checks for type ax 5. count number of cm audits 6. count number of cm spec checks 7. count number of ax audits 8. count number of ax spec checks as you can see its quite a few queries, but they all work, and work fast, but only if there is data in the db for given day. if any of the queries return no records the page just wont load ( i get "The page cannot be displayed" error message from browser). I tried to place or die to return string "no audits" when query returned empty but to no avail. Any tips on that one. Here's the code - I warned you it's a bit messy: <p class="report-font-header"><b>CM Audit</b></p> <p> <?PHP function showsql($MySQL,$MyID="No ID") { echo '<hr>'; echo '<p>'.$MyID.'</p>'; echo '<p>'.$MySQL.'</p>'; echo '<hr>'; } /////////------get data for cm audit echo "<table border=0 class=\"report-font-table\"><tr bgcolor=#CCCCCC><td><b>MODEL</b></td><td><b>SERIAL NUMBER</b></td><td><b>INSPECTOR</b></td><td><b>COMMENTS/FAILS</b></td></tr>"; $MySQL1 = 'select Model, Serial_no, Inspector, Comment from CM_Audit where Date=#'.$new_date.'#'; $MyCon=odbc_connect('SQA_Typewriter','','') or die ('No audits carried out on that day'); // use the SQA_Typewriter ODBC $result=odbc_exec($MyCon,$MySQL1); $rs = 0; // set count of array to be 0 for first run for($i = 0; $i < count($rs); ) { while ($rs = odbc_fetch_row($result)) { //divde the count by two and see if there is a remainder(odd number) and assign a color. $bgcolor = ($i % 2) ? '#CCFFFF' : '#CCFFCC'; //print results.... echo "<tr bgcolor=\"$bgcolor\"> <td>".odbc_result($result,"Model")."</td> <td >".odbc_result($result,"Serial_no")."</td> <td >".odbc_result($result,"Inspector")."</td> <td >".odbc_result($result,"Comment")."</td> </tr>"; //etc $i++; } odbc_close($MyCon); } print "</table>"; ?> </p> <!-- PRINT CM SPEC CHECKS ---> <p class="report-font-header"><b>CM SPEC CHECKS</b></p> <p> <?PHP /////////------get data for cm spec checks echo "<table border=0 class=\"report-font-table\"><tr bgcolor=#CCCCCC><td><b>PRODUCT CODE</b></td><td><b>MODEL</b></td><td><b>COUNTRY</b></td><td><b>INSPECTOR</b></td><td><b>COMMENTS/FAILS</b></td></tr>"; $MySQL2 = 'select Product_code, Model, Country, Inspector, Comment from CM_spec_check where Date=#'.$new_date.'#'; $MyCon=odbc_connect('SQA_Typewriter','','') or die ('No audits carried out on that day'); // use the SQA_Typewriter ODBC $result=odbc_exec($MyCon,$MySQL2); $rs = 0; // set count of array to be 0 for first run for($i = 0; $i < count($rs); ) { //while (odbc_fetch_row($MyResult)) while ($rs = odbc_fetch_row($result)) { //divde the count by two and see if there is a remainder(odd number) and assign a color. $bgcolor = ($i % 2) ? '#CCFFFF' : '#CCFFCC'; //print results.... echo "<tr bgcolor=\"$bgcolor\"> <td>".odbc_result($result,"Product_code")."</td> <td>".odbc_result($result,"Model")."</td> <td>".odbc_result($result,"Country")."</td> <td >".odbc_result($result,"Inspector")."</td> <td >".odbc_result($result,"Comment")."</td> </tr>"; //etc $i++; } odbc_close($MyCon); } print "</table>"; ?> </p> <!-------PRINT AX AUDIT----> <p class="report-font-header"><b>AX Audit</b></p> <?php //******************************************************* /////////---get data for ax audit echo "<table border=0 class=\"report-font-table\"><tr bgcolor=#CCCCCC><td><b>MODEL</b></td><td><b>SERIAL NUMBER</b></td><td><b>INSPECTOR</b></td><td><b>COMMENTS/FAILS</b></td></tr>"; $MySQL3 = 'select Model, Serial_no, Inspector, Comment from AX_Audit where Date=#'.$new_date.'#'; $MyCon=odbc_connect('SQA_Typewriter','','') or die ('No audits carried out on that day'); // use the SQA_Typewriter ODBC $result=odbc_exec($MyCon,$MySQL3); $rs = 0; // set count of array to be 0 for first run for($i = 0; $i < count($rs); ) { //while (odbc_fetch_row($MyResult)) while ($rs = odbc_fetch_row($result)) { //divde the count by two and see if there is a remainder(odd number) and assign a color. $bgcolor = ($i % 2) ? '#CCFFFF' : '#CCFFCC'; //print results.... echo "<tr bgcolor=\"$bgcolor\"> <td>".odbc_result($result,"Model")."</td> <td >".odbc_result($result,"Serial_no")."</td> <td >".odbc_result($result,"Inspector")."</td> <td >".odbc_result($result,"Comment")."</td> </tr>"; //etc $i++; } odbc_close($MyCon); } print "</table>"; ?> <!-- PRINT AX SPEC CHECKS ---> <p class="report-font-header"><b>AX Spec Checks</b></p> <?PHP /////////------get data for cm spec checks echo "<table border=0 class=\"report-font-table\"><tr bgcolor=#CCCCCC><td><b>PRODUCT CODE</b></td><td><b>MODEL</b></td><td><b>COUNTRY</b></td><td><b>INSPECTOR</b></td><td><b>COMMENTS/FAILS</b></td></tr>"; $MySQL2 = 'select Product_code, Model, Country, Inspector, Comment from AX_spec_check where Date=#'.$new_date.'#'; $MyCon=odbc_connect('SQA_Typewriter','','') or die ('No audits carried out on that day'); // use the SQA_Typewriter ODBC $result=odbc_exec($MyCon,$MySQL2); $rs = 0; // set count of array to be 0 for first run for($i = 0; $i < count($rs); ) { //while (odbc_fetch_row($MyResult)) while ($rs = odbc_fetch_row($result)) { //divde the count by two and see if there is a remainder(odd number) and assign a color. $bgcolor = ($i % 2) ? '#CCFFFF' : '#CCFFCC'; //print results.... echo "<tr bgcolor=\"$bgcolor\"> <td>".odbc_result($result,"Product_code")."</td> <td>".odbc_result($result,"Model")."</td> <td>".odbc_result($result,"Country")."</td> <td >".odbc_result($result,"Inspector")."</td> <td >".odbc_result($result,"Comment")."</td> </tr>"; //etc $i++; } odbc_close($MyCon); } print "</table>"; ?> <p></p> <!-- COUNTING TOTALS--> <table border="0"> <tr><td class="report-font-header"><b>Total CM Audits:</b></td><td width="20" align="center"><b> <?php ///---COUNT AUDITS $ctSQL1 = 'select Count(*) AS cma from CM_Audit where Date=#'.$new_date.'#'; // Prepare SQL $MyCon=odbc_connect('SQA_Typewriter','',''); // use the SQA_Typewriter ODBC $MyResult=odbc_exec($MyCon,$ctSQL1) or die ('0'); // run the query against the ODBC $row = odbc_fetch_array($MyResult); echo $row['cma']; odbc_close($MyCon); ?></b></td><td class="report-font-header"><b>Total CM Spec Checks:</b></td><td width="20" align="center"><b> <?php ///---COUNT AUDITS $ctSQL2 = 'select Count(*) AS cmsp from CM_spec_check where Date=#'.$new_date.'#'; // Prepare SQL $MyCon=odbc_connect('SQA_Typewriter','',''); // use the SQA_Typewriter ODBC $MyResult=odbc_exec($MyCon,$ctSQL2) or die ('0'); // run the query against the ODBC $row = odbc_fetch_array($MyResult); echo $row['cmsp']; odbc_close($MyCon); ?> </b></td></tr><tr><td class="report-font-header"><b>Total AX Audits:</b></td><td width="20" align="center"><b> <?php ///---COUNT AX AUDITS $ctSQL3 = 'select Count(*) AS axa from AX_Audit where Date=#'.$new_date.'#'; // Prepare SQL $MyCon=odbc_connect('SQA_Typewriter','',''); // use the SQA_Typewriter ODBC $MyResult=odbc_exec($MyCon,$ctSQL3) or die ('0'); // run the query against the ODBC $row = odbc_fetch_array($MyResult); echo $row['axa']; odbc_close($MyCon); ?></b></td><td class="report-font-header"><b>Total AX Spec Checks:</b></td><td width="20" align="center"><b> <?php ///---COUNT AX SPEC CHECKS $ctSQL4 = 'select Count(*) AS axsc from AX_spec_check where Date=#'.$new_date.'#'; // Prepare SQL $MyCon=odbc_connect('SQA_Typewriter','',''); // use the SQA_Typewriter ODBC $MyResult=odbc_exec($MyCon,$ctSQL4) or die ('0'); // run the query against the ODBC $row = odbc_fetch_array($MyResult); echo $row['axsc']; odbc_close($MyCon); ?> </b></td></tr></table> Quote Link to comment https://forums.phpfreaks.com/topic/207811-page-not-loading-when-empty-record-in-db-using-odbc/ Share on other sites More sharing options...
niwa3836 Posted July 15, 2010 Share Posted July 15, 2010 Hi, I havent had chance to study the code in depth but just picking up on something you say about using die which I guess you are trying to use for troubleshooting. As you know "pages" dont load until its ready (ok there are exceptions but lets not going into those & flushing here). Personally for troubleshooting I use log files, i.e. function dodebug($string) { global $Basedir,$thisprocess ; if(!file_exists($Basedir.'debugs')) mkdir($Basedir.'/debugs/') ; $ff = fopen($Basedir."debugs/".date('Ymd')."-debug.dat","a") ; fwrite($ff,"[".date('H:i:s')."][".$thisprocess."] ".$string."\r\n") ; fclose($ff) ; return(1) ; } //dodebug you can then easily debug your code even when pages dont load. Also on the sql stuff you can test where it successully got the result or "a" result. Quote Link to comment https://forums.phpfreaks.com/topic/207811-page-not-loading-when-empty-record-in-db-using-odbc/#findComment-1086325 Share on other sites More sharing options...
psuplat Posted July 16, 2010 Author Share Posted July 16, 2010 I tried your debugging solution, unfortunatelly it doesn't seem to work for me. Any ideas how to tackle this Quote Link to comment https://forums.phpfreaks.com/topic/207811-page-not-loading-when-empty-record-in-db-using-odbc/#findComment-1086929 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.