show only records that have data in a particular column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

show only records that have data in a particular column

Post by inosent1 »

Code: Select all


<?PHP
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$fetch = mysql_query("SELECT * FROM table LIMIT 0, 10") or
die(mysql_error());
?>

the above pulls the data, the first 10, and then a next link will show 10 at a time until the end of the table, etc

but what i want is to pull records only if a particular field in that row is not empty.

how do i do this?

thanks
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: show only records that have data in a particular column

Post by twinedev »

Well it depends what you mean by "empty":

for blank string:

SELECT * FROM table WHERE field<>"" LIMIT 0,10

for a null value:

SELECT * FROM table WHERE field IS NOT NULL LIMIT 0,10
fffengcharger
Forum Newbie
Posts: 1
Joined: Thu Jul 21, 2011 3:23 am
Location: http://www.samsung-battery-charger.co.uk/

Re: show only records that have data in a particular column

Post by fffengcharger »

thank you for share.
Post Reply