Jump to content

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.

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.