Page 1 of 1

empty array?

Posted: Sun May 02, 2010 6:27 pm
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 (:

Re: empty array?

Posted: Sun May 02, 2010 6:55 pm
by requinix
Modify your query to not return those "empty" rows.

Re: empty array?

Posted: Sun May 02, 2010 7:04 pm
by robynprivette
how would i go about that? i'm still learning (:

Re: empty array?

Posted: Sun May 02, 2010 10:45 pm
by requinix
I don't know. What does it look like if it's "empty"?

Re: empty array?

Posted: Mon May 03, 2010 1:48 am
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.

Re: empty array?

Posted: Wed May 05, 2010 12:13 pm
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: