php/mysql help needed - hiding or showing a table based on mysql

Discussion in 'PHP' started by SwiftKiwi, Sep 21, 2009.

  1. #1
    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
     
    SwiftKiwi, Sep 21, 2009 IP
  2. caprichoso

    caprichoso Well-Known Member

    Messages:
    433
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    110
    #2
    You won't get an answer unless you put your tables structure and current (relevant) PHP code here.
     
    caprichoso, Sep 21, 2009 IP
  3. dweebsonduty

    dweebsonduty Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    Digital Goods:
    1
    #3
    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:
     
    dweebsonduty, Sep 21, 2009 IP
  4. SwiftKiwi

    SwiftKiwi Guest

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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:
     
    SwiftKiwi, Sep 21, 2009 IP