Jump to content

[SOLVED] not printing rows with no data


lilbadger25

Recommended Posts

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

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).

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.