Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing valid fields only

Status
Not open for further replies.

GWHicks

Programmer
Dec 11, 2002
39
US
I am trying to compile a listing of records from my database where it compiles a set of fields into a group together. However if some fields are empty I want it to completely skip that line (without leaving a blank line). What is the best way to do this?

Currently I am echoing the field and then using an html break to go to the next line. I have considered storing the <br> command in my database when the record gets stored but that seems rather sloppy. Is there a way to get php to skip over a field that is blank and continue on the listing?

Thanks.

Greg

P.S. If you want to see the current working model it is at Use 15008 for a full listing of returned values, and 15019 to see what it does with blank field entries.

Greg Hicks
VB.Net (Newbie) Programmer
 
why not assign the values to variables first and then check for the null or empty field and skip

$field1=$rows['field1'];
$field2=$rows['field2'];

if ((!is_null($field1))||(!is_null($field2)){
//show results here

}//end if

then if one is null the entire record is skipped

hth

Bastien

cat, the other other white meat
 
I am not sure we are talking the same thing here. What I am looking for is that some fields will be null on every record. Those fields I don't want to show a blank line for.

EX:

P20 Core and Cavity
H13 Slides
Other items

Between P20 Core and H13 Slides in my setup are other options that could have been chosen by the user. When they don't select them it needs to compile the list as I have it above instead of this way:

P20Core and Cavity




H13 Slides
Other items

The white space between my items is what I am trying to remove. I am assigning the fields to variables, and then listing them like this:

<? echo &quot;$p20corecav&quot;; ?><br>
<? echo &quot;$h13corecav&quot;; ?><br>
<? echo &quot;$sscorecav&quot;; ?><br>
<? echo &quot;$alumcorecav&quot;; ?><br>
<? echo &quot;$othercav&quot;; ?><br>
<? echo &quot;$othercore&quot;; ?><br>
<? echo &quot;$p20slides&quot;; ?><br>
<? echo &quot;$h13slides&quot;; ?><br>
ETC

I have tried this code to only read the line if the variable is not null (there is something there to post)

<? if ($p20corecav != &quot;&quot;) {
echo &quot;$p20corecav&quot;
<br>;
}?>

But I get a parse error with that in place.

Thanks for whatever tips anyone can offer.
Greg Hicks

Greg Hicks
VB.Net (Newbie) Programmer
 
The parse error is because you left off the semicolon at the end of your echo statement.

In another interpretation, you might say you prematurely closed your string literal.

Try:
<?
if ($p20corecav != &quot;&quot;)
{
echo $p20corecav . '<br>';
}
?>


I'm not sure I'm understanding what it is you're trying to do, either.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
That did what I was looking for. Just wanted to eliminate wasted white space between items with no information stored in the field.
Greg

Greg Hicks
VB.Net (Newbie) Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top