I am having a problem with a field a mysql table that can be any single letter or a Null ie: nothing entered
The field default is Not Null and is called sufix
My code at present looks like this
Code:
<?php
$tble = 'mytable;
$modnum = 30201;
$suff = ''; // NULL but can be A or 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) {
$db .= "AND sufix = '$suff'";
}
if ($result = mysqli_query($connect,$db)) {
if (mysqli_num_rows($result)) {
while ($row = mysqli_fetch_assoc($result)){
?>
<table>
-
-
-
-
</table>
<?php
}
}
}
?>
As is. It finds the record with the null as expected
By it goes wrong when I put in A or B when it then shows all three records
I need it to just show the one selected by $suff
if I change this line
if (!$suff) {
to
if ($suff) {
then it finds the A or B but prints all 3 when I select NULL
Please help is needed
Thanks
Roy..