jeet Posted August 23, 2013 Share Posted August 23, 2013 <?phpif(isset($_GET['b_no'])){$bno=$_GET['b_no'];include("connect.php");$query19="select * from billing where `b_no`=$bno";$rs19=$conn->execute($query19);if($rs19){$itm=explode(',',$rs19['item']);$qty=explode(',',$rs19['qty']);$r=count($itm); for($i=0;$i<=$r;$i++) { if(isset($itm[$i]) && isset($qty[$i])) {echo "item".$itm[$i];echo "qty".$qty[$i];echo "<br>"; }}}else {echo "no records found";}}else {echo "enter bill no";}?> this is my code for fetching records by passing a bill number . it runs fine if i pass a bill number which is present in the table but if i pass a bill number ($bno ) which is not present in the billing table then also the control goes to if statement and executes explode function and all.basically my question is how to validate hte select query . Quote Link to comment https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/ Share on other sites More sharing options...
kicken Posted August 23, 2013 Share Posted August 23, 2013 Without knowing what $conn->execute does, we can't say much about how your code is going to process. Based on your description it sounds as though it will return a true-ish value regardless of if actual rows are found or not. If that is the case you will need to find another way of determining whether a row was actually found. If you provide details on what $conn->execute does, by providing it's source for example, perhaps we can further help you figure out how to properly detect an empty result set. Also, for future reference, you need to enclose your code within tags when you post it. Failure to do so will greatly decrease your chances of getting help. Quote Link to comment https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/#findComment-1446437 Share on other sites More sharing options...
jeet Posted August 23, 2013 Author Share Posted August 23, 2013 (edited) <?php $conn = new COM ("ADODB.Connection") or die("Cannot start ADO"); $connStr = "PROVIDER=Microsoft.Ace.OLEDB.12.0;Data Source= C:\Arihant_billing\db\arihant_thali.accdb"; $conn->open($connStr); ?> this code is in connect.php Edited August 23, 2013 by jeet Quote Link to comment https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/#findComment-1446453 Share on other sites More sharing options...
jeet Posted August 23, 2013 Author Share Posted August 23, 2013 <?php if(isset($_GET['b_no'])){ $bno=$_GET['b_no']; include("connect.php"); $query19="select * from billing where `b_no`=$bno"; $rs19=$conn->execute($query19); if($rs19){ $itm=explode(',',$rs19['item']); $qty=explode(',',$rs19['qty']); $r=count($itm); for($i=0;$i<=$r;$i++) { if(isset($itm[$i]) && isset($qty[$i])) { echo "item".$itm[$i]; echo "qty".$qty[$i]; echo "<br>"; } } } else { echo "no records found"; } } else { echo "enter bill no"; } ?> this is my code for fetching records by passing a bill number . it runs fine if i pass a bill number which is present in the table but if i pass a bill number ($bno ) which is not present in the billing table then also the control goes to if statement and executes explode function and all. basically my question is how to validate hte select query . Quote Link to comment https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/#findComment-1446454 Share on other sites More sharing options...
mikosiko Posted August 23, 2013 Share Posted August 23, 2013 (edited) with this line: if($rs19){ ..... you are testing if the Execute() method was indeed able to execute correctly the SQL sentence and return a valid recordset, however, as kicken pointed out before, that doesn't guarantee that the select effectively returned rows or not, and you are not checking/validating that condition. What you probably want to do is more or less this (only relevant code shown): $query19="select * from billing where `b_no`=$bno"; $rs19=$conn->execute($query19); if (!$rs19) { // validate that a valid recordset has been generated without errors or not print $conn->ErrorMsg(); exit(); // maybe you want to stop the script in case of error } else { // We have a valid record set (could be empty), one option is validate that it is not empty, other is loop the recordset WHILE it hasn't reached the EOF if ($rs19->EOF) { echo "No Records found... (or recordset exhausted)"; // do something else or exit } else { // Green light... rest of your code } } [EDIT]: this link could help : http://phplens.com/lens/adodb/docs-adodb.htm Edited August 23, 2013 by mikosiko Quote Link to comment https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/#findComment-1446456 Share on other sites More sharing options...
jeet Posted August 24, 2013 Author Share Posted August 24, 2013 Thanks .the above code worked properly Quote Link to comment https://forums.phpfreaks.com/topic/281491-ms-access-2007-and-php/#findComment-1446565 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.