Jump to content

IS NOT NULL not filtering


dflow

Recommended Posts

hi

 

im trying to filter records in a record set according to the following sql :

SELECT *

FROM `region_list`

WHERE `RegionName` IS NOT NULL

 

as you understand i want to get all the records that their fileds are filled with a RegionName

 

for some reason it isnt working im testing it in my phpmyadmin interface and get no errors just the whole table with no filitering

 

RegionName  varchar(255)  utf8_unicode_ci    NULL No 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/132427-is-not-null-not-filtering/
Share on other sites

When you input a row into the table, are you distinctly setting the value to NULL, or ''  because there is a difference.

 

This may help

SELECT *
FROM `region_list`
WHERE (`RegionName` IS NOT NULL AND `RegionName` <> '')

 

That should check for both.

hi again i jumped the gun:

 

in the phpmyadmin it works aswell as in DREAMWEAVER

 

but on the site i get  a query error:

 

Warning: mysql_fetch_assoc(): 3 is not a valid MySQL result resource in /home/www/mysite.com/include/region_list_footer.php on line 62

 

here s the code:

<?php require_once('../Connections/international.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

 

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

 

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

mysql_select_db($database_international, $international);

$query_RsRegions = "SELECT *

FROM `region_list`

WHERE (

`RegionName` IS NOT NULL

AND `RegionName` <> ''

)";

$RsRegions = mysql_query($query_RsRegions, $international) or die(mysql_error());

$row_RsRegions = mysql_fetch_assoc($RsRegions);

$totalRows_RsRegions = mysql_num_rows($RsRegions);

mysql_free_result($RsRegions);

?>

<table width="200" border="0">

  <tr>

    <th scope="col"><table >

      <tr>

        <?php

$RsRegions_endRow = 0;

$RsRegions_columns = 3; // number of columns

$RsRegions_hloopRow1 = 0; // first row flag

do {

    if($RsRegions_endRow == 0  && $RsRegions_hloopRow1++ != 0) echo "<tr>";

  ?>

        <td><?php echo $row_RsRegions['RegionName']; ?></td>

        <?php  $RsRegions_endRow++;

if($RsRegions_endRow >= $RsRegions_columns) {

  ?>

      </tr>

      <?php

$RsRegions_endRow = 0;

  }

} while ($row_RsRegions = mysql_fetch_assoc($RsRegions));

if($RsRegions_endRow != 0) {

while ($RsRegions_endRow < $RsRegions_columns) {

    echo("<td> </td>");

    $RsRegions_endRow++;

}

echo("</tr>");

}?>

    </table></th>

  </tr>

</table>

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.