Closed Thread
Results 1 to 9 of 9

Thread: if statement

  1. #1
    hudbarnett is offline Newbie
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    if statement

    Hi all

    I would like to add to my web form a section where the user can select yes or no. The reason for this is that if they select yes then his / her details will be displayed using the code below. What i need to know is how i create the if statement on the following code?

    i understand that it would work in the following way but i'm not sure how to code it in.

    if the user selects Yes then show all results

    else

    do not display the users details

    Code:
    <?php
    $con = mysql_connect("localhost","db_username","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("db_name", $con);
    
    $result = mysql_query("SELECT * FROM members");
    
    echo "<table border='1'>
    <tr>
    <th>Email Address</th>
    <th>Title</th>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Address</th>
    <th>Mobile</th>
    <th>Tennis Number</th>
    <th>LTA Number</th>
    <th>ITF ITN Number</th>
    <th>Age</th>
    <th>Club</th>
    </tr>";
    
    while($row = mysql_fetch_array($result)) {
        echo "<tr>";
        echo "<td><a href='mailto:{$row['username']}'>{$row['username']}</a></td>";
        echo "<td>" . $row['title'] . "</td>";
        echo "<td>" . $row['showdetails'] . "</td>";
        echo "<td>" . $row['firstname'] . "</td>";
        echo "<td>" . $row['lastname'] . "</td>";
        echo "<td>" . $row['address'] . "</td>";
        echo "<td>" . $row['mobile'] . "</td>";
        echo "<td>" . $row['tennis_number'] . "</td>";
        echo "<td>" . $row['lta_number'] . "</td>";
        echo "<td>" . $row['itf_itn_number'] . "</td>";
        echo "<td>" . $row['age'] . "</td>";
        echo "<td>" . $row['club'] . "</td>";
        echo "</tr>";
    }  echo "</table>";
    
    mysql_close($con);
    ?>
    Thanks

    Hud

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    DEViANT's Avatar
    DEViANT is offline Programming Expert
    Join Date
    Aug 2010
    Location
    South Africa
    Posts
    359
    Blog Entries
    4
    Rep Power
    8

    Re: if statement

    Will the yes/no be posted, or saved to a database?

  4. #3
    hudbarnett is offline Newbie
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    Re: if statement

    Hi there

    The Yes or No is only going to be held in the database. I just need the user to say Yes if they wish their details to be listed

    Does that help?

    Thanks

    Hud

  5. #4
    DEViANT's Avatar
    DEViANT is offline Programming Expert
    Join Date
    Aug 2010
    Location
    South Africa
    Posts
    359
    Blog Entries
    4
    Rep Power
    8

    Re: if statement

    Whats the table name going to be where you save the yes/no ?

  6. #5
    hudbarnett is offline Newbie
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    Re: if statement

    Hi

    The table name in the database is called members and the dropdown on the page for capturing the value is called showdetails

    Thanks

    Hud

  7. #6
    DEViANT's Avatar
    DEViANT is offline Programming Expert
    Join Date
    Aug 2010
    Location
    South Africa
    Posts
    359
    Blog Entries
    4
    Rep Power
    8

    Re: if statement

    Well, sounds like a simple SQL querie change to me?

    Code:
    $result = mysql_query("SELECT * FROM members WHERE showdetails = 'yes'");
    Just change yes to whatever your yes/no value is in your SQL database.

  8. #7
    hudbarnett is offline Newbie
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    Re: if statement

    Thanks, i'll give that a try just now

  9. #8
    hudbarnett is offline Newbie
    Join Date
    Jan 2010
    Posts
    23
    Rep Power
    0

    Re: if statement

    Works perfect... Thanks for your help

  10. #9
    DEViANT's Avatar
    DEViANT is offline Programming Expert
    Join Date
    Aug 2010
    Location
    South Africa
    Posts
    359
    Blog Entries
    4
    Rep Power
    8

    Re: if statement

    Your very welcome. Glad I could help

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. i need help.....what the mean of this statement?
    By amr magdey in forum C# Programming
    Replies: 1
    Last Post: 04-24-2011, 02:15 PM
  2. help with if-statement
    By Root23 in forum Java Help
    Replies: 2
    Last Post: 10-15-2010, 10:30 AM
  3. Need help with if statement.
    By hayschooler in forum PHP Development
    Replies: 0
    Last Post: 04-15-2010, 06:20 PM
  4. SQL Statement
    By thieflock in forum Java Help
    Replies: 3
    Last Post: 05-04-2009, 09:15 PM
  5. Help with this FOR XML EXPLICIT statement
    By hoser2001 in forum JavaScript and CSS
    Replies: 5
    Last Post: 08-01-2006, 11:37 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts