empty array?

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
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

empty array?

Post by robynprivette »

I've been trying to find the answer by searching the web but i keep coming up empty handed.... i have entries in a database that i'm trying to echo onto my site but the empty fields are being echoed as well... here is my code

Code: Select all

<?php
mysql_connect("localhost","",""); 
	

mysql_select_db(""); 


if(!isset($cmd)) 
{
   
   $result = mysql_query("select * from dragons order by id"); 
   
   
   while($r=mysql_fetch_array($result)) 
   { 
      
      $egg=$r["egg"];
      $hatch=$r["hatch"];
      $id=$r["id"];
     
	 
      echo "<img src='http://dragcave.net/image/$egg.gif'>";
      echo "<a href='stafftest.php?cmd=delete&id=$id'>$egg <font color='red'>x</a>";
      echo "<br>";
      echo "<img src='http://dragcave.net/image/$hatch.gif'>";
      echo "<a href='stafftest.php?cmd=delete&id=$id'>$hatch <font color='red'>x</a>";
      echo "<br>";
    }
}
?>
There are some "egg" entries and "hatch" entries in the database that are empty and i don't want those printed out....

see ex. here
http://www.thehatchingdragons.com/stafftest.php

Thanks (:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: empty array?

Post by requinix »

Modify your query to not return those "empty" rows.
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

Re: empty array?

Post by robynprivette »

how would i go about that? i'm still learning (:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: empty array?

Post by requinix »

I don't know. What does it look like if it's "empty"?
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: empty array?

Post by Apollo »

Change your query into something like:

Code: Select all

select * from dragons where not (egg='' or hatch='' or egg is null or hatch is null) order by id
But better pick up some basics on SQL, that'd probably help you much more.
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

Re: empty array?

Post by robynprivette »

Apollo wrote:Change your query into something like:

Code: Select all

select * from dragons where not (egg='' or hatch='' or egg is null or hatch is null) order by id
But better pick up some basics on SQL, that'd probably help you much more.
Thank you SO much Apollo (: That worked perfectly! I knew it would be something simple that would make me feel dumb! LoL :crazy:
Post Reply