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
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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.