I am making a contact list php/mysql script and each contact can have up to ten websites. When I list the contacts details and for example they have one website listed it will look like this: Website 1: foobar.com Website 2: Website 3: etc etc If there is a value present under Website 2, I want to echo a table that lists $website2, else echo nothing... I have tried WHERE EXISTS etc but I can't seem to put it together... Database: cls Table: contacts
Select everything, and echo only when there is data dont copy this code because it is not complete but try to understand it. while($row = mysql_fetch_array($result)) { $website = $row["website"]; if ($website) { //echo table } } PHP:
Thanks dweebsonduty! Here's what I did: include 'config.php'; $query="SELECT * FROM contacts WHERE website2='$website2'"; $result=mysql_query($query); while($row = mysql_fetch_array($result)) { $website2 = $row["website2"]; if ($website2) { // table } } mysql_close(); PHP: