Jump to content

Erratic Behaviour in a Select statement


Topshed

Recommended Posts

My Select script is behaving very strangely

 

Sometime I get a Blank screen for one number (like the record does not exist) and the expected result from another

so a code snippit to report a failure to find the record would help

 

it is run from a template so only the two inputs change ?

 

<?php
$tble = 'aefe';
$modnum = 10000;         //INPUT A
$suff = '';              //INPUT B

include_once"../includes/My_conn.php";
    $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database");
    $db = mysqli_select_db($connect,"$dbname") OR DIE( "Unable to select database ");
    $db = "SELECT * FROM $tble WHERE model = $modnum ";
   if ($suff) {
		}   else   {
             $db .= "AND sufix = '$suff'";
    }
if ($result = mysqli_query($connect,$db)) {  
	if (mysqli_num_rows($result)) {
	$row = mysqli_fetch_assoc($result)
//                    while ($row = mysqli_fetch_assoc($result)){
   
                
?>
<table>
-
-
-
-
</table>
}
}
?>

 

If I replace the row with the while row that is commented out it does work sort of but gives me all records with that modnum if I enter  $suff = '';  //INPUT B

but find the other records with any other letter

if I change

if ($suff) {

      to 

if (!$suff) {

The whole result thing  is reversed

 

Thanks

 

Roy...

 

Link to comment
https://forums.phpfreaks.com/topic/93599-erratic-behaviour-in-a-select-statement/
Share on other sites

btherl  wrote

 

I recommend printing out $db for verification.  It may not be what you expect.

 

Oh how right you were,

I have solved all my problems with this script AND deleted half dozen lines of code in the process

 

Thank you for the help

 

Regards

Roy..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.