Forum Moderators: coopster

Message Too Old, No Replies

filtering out "no data entered"

Query to perform task

         

henry0

12:55 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I perform the following query

select bus_name, first_name, last_name, fax,user_name from bol_ag where fax like fax

I need to select only businesses that have entered a fax number
fax has been set to null

I tried many flavors of "like" and "where"
but still grab the empty fields along with the fax number provided

how can I weed out of my list fax empty data

thanks

regards

Henry

mogwai

1:37 pm on Dec 13, 2003 (gmt 0)

10+ Year Member



"I need to select only businesses that have entered a fax number
fax has been set to null "

SELECT bus_name, first_name, last_name, fax, user_name
FROM bol_ag
WHERE fax IS NOT NULL

lorax

1:39 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



SELECT bus_name, first_name, last_name, fax,user_name
FROM bol_ag
WHERE fax = '$fax';

I modified your where statement to look for an exact match. If you want it to look for similar fax numbers then:

WHERE fax LIKE '$fax' AND fax <> '';

This is from memory (no testing and no coffee) so you'd best take a look at the string comparison [mysql.com] and comparison operators [mysql.com] pages at MySQL[/url] to be sure.

henry0

1:51 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Mogway I tried that before and even changed back DB to null and not null but it did not work

Lorax that might work
I will try it and report

thanks

regards

Henry

lorax

2:19 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My <> sytax should probably be changed to IS NOT

henry0

2:36 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Introducing a value to $fax is not working for $ fax does not exist
I use 2 scripts

one is part of an "enter data script"

$fields_displayed = array(bus_name, first_name, last_name, fax,user_name);
$fields_displayed_list = "bus_name, first_name, last_name, fax,user_name";

and then I generate a CVS report with the entered data:

if (isset($data))
{

if ($data=="display")

$report_string .= "bus_name, first_name, last_name, fax,user_name\n";
$query="select bus_name, first_name, last_name, fax,user_name from bol_ag where fax like fax ";

$data = $the_db -> selectquery($query);
create_report();
}
etc....

well that was two years ago
now I offer a regular form that pass $this and that ...
but I have 2000 ref in that sector so I cannot modif in depth.
but still need to generate a report with existing fax #

lorax

5:57 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



wait a minute... so there is no value for $fax in the WHERE statement? If you're just looking for all of the records that have something in the field called 'fax' then you need to do as mogwai suggested.

WHERE fax IS NOT NULL or WHERE fax IS NOT 'NULL' will yield all records where the field is filled in with a default NULL

WHERE fax IS NOT '' will yield all records where the field is not empty

henry0

6:29 pm on Dec 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks
I got it now

lorax

3:03 am on Dec 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Re: syntax

I was right in the first place <>