natie769 Posted April 22, 2009 Share Posted April 22, 2009 I have a form that submits the data to mysql. Then on the page where it displays all the rows in the table (items) I want it to only show the form fields (or columns) that have been filled out. So I'm trying to check if it is empty. I'm using a code that does that now -- but it only works for the first entry in the database, and then applies that to each and every entry after it (even though it isn't true)**. Should I be using a for loop so it checks every database table entry, and not just the first entry? ** When I say it applies to each and every entry I mean if the first entries "Category" is empty, it thinks the rest of the table entries "Category" is empty, when in fact it isn't. Hope that makes sense... Any help is appreciated! $result = mysql_query("SELECT * FROM `Equipment Listings` WHERE id = $id"); while($row = mysql_fetch_assoc($result)){ echo '<table>'; //CATEGORY if (isset($_POST['category'])) { echo '<tr><td><span class="equipmentheader">Category:</span> '; echo $row['category']; echo '</td></tr>'; } else { echo ''; } //YEAR if (isset($_POST['year'])) { echo '<tr><td><span class="equipmentheader">Year:</span> '; echo $row['year']; echo '</td></tr>'; } else { echo ''; } //SERIAL NUMBER if (isset($_POST['serialnum'])) { echo '<tr><td><span class="equipmentheader">Serial Number:</span> '; echo $row['serialnum']; echo '</td></tr>'; } else { echo ''; } Quote Link to comment https://forums.phpfreaks.com/topic/155184-how-to-check-if-a-field-is-empty/ Share on other sites More sharing options...
kickstart Posted April 22, 2009 Share Posted April 22, 2009 Hi Do you mean to be checking the $_POST fields. Quick guess and I think what you are trying to get is:- $result = mysql_query("SELECT * FROM `Equipment Listings` WHERE id = $id"); while($row = mysql_fetch_assoc($result)) { echo '<table>'; //CATEGORY if (isset($row['category'])) { echo '<tr><td><span class="equipmentheader">Category:</span> '; echo $row['category']; echo '</td></tr>'; } else { echo ''; } //YEAR if (isset($row['year'])) { echo '<tr><td><span class="equipmentheader">Year:</span> '; echo $row['year']; echo '</td></tr>'; } else { echo ''; } //SERIAL NUMBER if (isset($row['serialnum'])) { echo '<tr><td><span class="equipmentheader">Serial Number:</span> '; echo $row['serialnum']; echo '</td></tr>'; } else { echo ''; } } All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/155184-how-to-check-if-a-field-is-empty/#findComment-816500 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.