TutorMe Posted September 3, 2007 Share Posted September 3, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/67806-specific-ifthen/ Share on other sites More sharing options...
TheFilmGod Posted September 3, 2007 Share Posted September 3, 2007 sure: // Makes life easier $year = $row['year'] if ($year == "0") { echo "<td>Year Hidden</td>"; } else { echo "<td>$year</td>"; } Quote Link to comment https://forums.phpfreaks.com/topic/67806-specific-ifthen/#findComment-340764 Share on other sites More sharing options...
TutorMe Posted September 3, 2007 Author Share Posted September 3, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/67806-specific-ifthen/#findComment-340767 Share on other sites More sharing options...
TutorMe Posted September 3, 2007 Author Share Posted September 3, 2007 I tried to replace echo "<td>" . $row['year'] . "</td>"; with your code, but it didn't help. I tried different variations also, but still to no avail. Quote Link to comment https://forums.phpfreaks.com/topic/67806-specific-ifthen/#findComment-340778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.