Jump to content

if statement

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
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

<?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
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Will the yes/no be posted, or saved to a database?

#3
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
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

#4
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Whats the table name going to be where you save the yes/no ?

#5
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
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

#6
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Well, sounds like a simple SQL querie change to me?

$result = mysql_query("SELECT * FROM members [COLOR="SeaGreen"]WHERE showdetails = 'yes'[/COLOR]");

Just change yes to whatever your yes/no value is in your SQL database.

#7
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
Thanks, i'll give that a try just now :)

#8
hudbarnett

hudbarnett

    Newbie

  • Members
  • PipPip
  • 23 posts
Works perfect... Thanks for your help

#9
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Your very welcome. Glad I could help :)