Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a little problem and I know

Status
Not open for further replies.

cs7536

Programmer
Apr 20, 2003
130
US
I have a little problem and I know it is simple but can;t think. My script is as followed:

<?php
$db = mysql_connect(&quot;host_name&quot;, &quot;user&quot;, &quot;password&quot;);
mysql_select_db(&quot;databse_name&quot;, $db);
$result = mysql_query(&quot;SELECT * FROM images ORDER BY id DESC LIMIT 1&quot;);

while($row = mysql_fetch_assoc($result)){
echo $row['image'];
}
?>

My issue is that when I display my page it displays all of the records in the image fileds even the records that do not have an image name in them. the images show up that have an image name in them and the records that do not contain an image name display an image boxe with a broken links.

How do I write a code that saids to display only the records that have an image name in the image field and not display the records that do not have anything in that field.

All help will be appreciated in advance.
Max

Nothing is hard when you realy want to learn it.

Max
 
Change your sql statement to something like

SELECT * FROM images WHERE imagename<>' ' ORDER BY id DESC LIMIT 1

MrBelfry
 
thanks that worked what does the <> stand for I never seen it used like that before, less than greater than but can you explain how id gets rid of the records that I did not want to see?..

Thanks
Max

Nothing is hard when you realy want to learn it.

Max
 
<> is a 'not equal' operator. It is the same as the != operator.

Since you are working with a character/varchar field you can also use the string functions and test for not zero length:

SELECT * FROM images where LENGTH(imagename)>0
 
Thansk alot MrBelfry and DRj478 I much appreciate you guys for the input


Max.

Nothing is hard when you realy want to learn it.

Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top