Jump to content

Recommended Posts

This may be confusing, so I apologize if it is.  I have a code that displays a value from a row in a mysql db.  The code is this:

echo "<td>" . $row['year'] . "</td>";

 

When the user submits their information, there is an option that says "hide the year I was born."  Since the row for "year" is set it INT, if they choose that option it returns "0."

 

I was wondering if there was a way to do something like

if $row['year'] = "0"{
echo"hidden by request"
}
else{
echo "<td>" . $row['year'] . "</td>";
}

 

but still have it work with my existing code.

 

Link to comment
https://forums.phpfreaks.com/topic/67806-specific-ifthen/
Share on other sites

Thanks.  This looks like what I'm looking for, but I'm a complete noob.  I'm gonna post the full code.  Do you think you could show me where I need to put your code to make it work?

<?php
require_once('config.php');
//first month
$result = mysql_query("SELECT * FROM January");

echo "<p>January:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM February");

echo "<p>February:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM March");

echo "<p>March:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM April");

echo "<p>April:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM May");

echo "<p>May:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM June");

echo "<p>June:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM July");

echo "<p>July:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM August");

echo "<p>August:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM September");

echo "<p>September:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM October");

echo "<p>October:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM November");

echo "<p>November:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
//next month
$result = mysql_query("SELECT * FROM December");

echo "<p>December:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";
mysql_close($con);
?>

 

To try to sum it up,

echo "<p>January:</p>
<p><table border='1'>
<tr>
<th>Username</th>
<th>Day</th>
<th>Year</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['username'] . "</td>";
  echo "<td>" . $row['day'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "</tr>";
  echo "</p>";
  }
echo "</table>";

is for each month.  If you cold just place it where it needs to go within there it would be great.

 

I apologize again for being such a nub.  I'll give you credit on the site if you wish.

 

 

Link to comment
https://forums.phpfreaks.com/topic/67806-specific-ifthen/#findComment-340767
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.