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
robynprivette
Forum Commoner
Posts: 46 Joined: Sun May 02, 2010 6:22 pm
Post
by robynprivette » Sun May 02, 2010 6:27 pm
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 (:
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun May 02, 2010 6:55 pm
Modify your query to not return those "empty" rows.
robynprivette
Forum Commoner
Posts: 46 Joined: Sun May 02, 2010 6:22 pm
Post
by robynprivette » Sun May 02, 2010 7:04 pm
how would i go about that? i'm still learning (:
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun May 02, 2010 10:45 pm
I don't know. What does it look like if it's "empty"?
Apollo
Forum Regular
Posts: 794 Joined: Wed Apr 30, 2008 2:34 am
Post
by Apollo » Mon May 03, 2010 1:48 am
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.
robynprivette
Forum Commoner
Posts: 46 Joined: Sun May 02, 2010 6:22 pm
Post
by robynprivette » Wed May 05, 2010 12:13 pm
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