lilbadger25 Posted January 30, 2008 Share Posted January 30, 2008 I have a table with 6 possible "tech_info" fields in my table, but there are times that all 6 won't be filled out. Currently, I have all 6 outputs showing on the target page, even if there is no info in some of the fields. A friend suggested using the following code: <?php $techinfo1 = $row_rsGetProd['tech_info1']; $techinfo2 = $row_rsGetProd['tech_info2']; $techinfo3 = $row_rsGetProd['tech_info3']; $techinfo4 = $row_rsGetProd['tech_info4']; $techinfo5 = $row_rsGetProd['tech_info5']; $techinfo6 = $row_rsGetProd['tech_info6']; foreach ($row_rsGetProd as $value) { if ($value == "") { echo "<img src='images/dotArrow2.jpg' hspace='3'/>$value<br>"; echo "<img src='images/tech_infoLine.jpg' vspace='5' /><br>"; } } But it's not working the way I was hoping. It's showing 9 lines in total (instead of the original 6 possible spaces). Can anyone explain why it's doing this, and how to make it only show the number of lines of text there are? Link to comment https://forums.phpfreaks.com/topic/88563-solved-not-printing-rows-with-no-data/ Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 <?php foreach ($row_rsGetProd as $value) { if ($value != "") { echo "<img src='images/dotArrow2.jpg' hspace='3'/>$value<br>"; echo "<img src='images/tech_infoLine.jpg' vspace='5' /><br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/88563-solved-not-printing-rows-with-no-data/#findComment-453383 Share on other sites More sharing options...
lilbadger25 Posted January 30, 2008 Author Share Posted January 30, 2008 Thanks Thorpe! I guess I forgot to mention that there are other fields for each product. Id, image, name, info, blah, blah, blah... It's all going into the little "tech info" box now. I need only the tech_info1, tech_info2...fields to go in that box (table on the target page). Link to comment https://forums.phpfreaks.com/topic/88563-solved-not-printing-rows-with-no-data/#findComment-453388 Share on other sites More sharing options...
trq Posted January 30, 2008 Share Posted January 30, 2008 The logic is the same, simply check if the field is empty or not. Link to comment https://forums.phpfreaks.com/topic/88563-solved-not-printing-rows-with-no-data/#findComment-453395 Share on other sites More sharing options...
scottybwoy Posted January 30, 2008 Share Posted January 30, 2008 By the way the line if ($value != "") { //Should be... if ($value !== "") { Otherwise that statement will always be true, even if there is an empty value, so as it is an comparison it should have two == signs. If you wanted $value to never equal an empty string you would use the first one, which is an assignment operator. Link to comment https://forums.phpfreaks.com/topic/88563-solved-not-printing-rows-with-no-data/#findComment-453427 Share on other sites More sharing options...
lilbadger25 Posted January 30, 2008 Author Share Posted January 30, 2008 Thanks for explaining that, Scotty. Now I understand... Link to comment https://forums.phpfreaks.com/topic/88563-solved-not-printing-rows-with-no-data/#findComment-453455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.