faqts : Computers : Programming : Languages : PHP : Common Problems : Arrays

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 10 people (80%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do you skip an empty field from a mysql_fetch_array so that the fields won't print

Apr 17th, 2002 13:46
Techek, Dan C,


You can take two approaches :
1) Only read the data from MySQL that you really want
2) Make some control-structures in PHP to sort out "wrong" records
Examples :
1) Using MySQL
If you only want to list records where the DB-attribute "name" contains 
a string you could use this query :
SELECT name WHERE name NOT LIKE "" OR name NOT NULL
That would give you records where name doesn't contain nothing or is 
not null.
2) Using PHP
<?php
while($row = mysql_fetch_array($link)) {
  if($row[name]) {
    echo "Name : $name<br>\n";
  }
}
?>
That would also list only records where name contains something, but 
it's a bit silly because if you have eg. 100000 records you're just 
burning a *LOT* of CPU-cycles for nothing!
Feel free to contact me if you need a better example (a working one 
perhaps?)