Forum Moderators: coopster

Message Too Old, No Replies

If... else statement, please help

         

Acternaweb

12:45 am on Jan 2, 2004 (gmt 0)

10+ Year Member



I am trying to set up this code so that if the value field is not greater then "1" then nothing should be displayed.

The first code works now but doesn't have a "rule" that is pasted below.

Appreciate your help

}
echo '<td><ul>';
echo '<LI STYLE="list-style-type: circle"> <b>player:</b> ';
echo $book['player'];
echo '<LI STYLE="list-style-type: circle"><b>team:</b> ';
echo $book['team'];
echo '<LI STYLE="list-style-type: circle"><b>current value:</b> ';
echo number_format($book['value'], 2);
echo '<LI STYLE="list-style-type: circle"><b>description:</b> ';
echo $book['description'];
echo '</ul></td></tr></table>';
}

if($value[0]>0)
echo '<LI STYLE="list-style-type: circle"><b>current value:</b> ';
echo number_format($book['value'], 2);

paladin

1:23 am on Jan 2, 2004 (gmt 0)

10+ Year Member



try
if($value[0]>0)
{
echo '<LI STYLE="list-style-type: circle"><b>current value:</b> ';
echo number_format($book['value'], 2);
...
...
...
...
}
else
{
//error message here
}

Acternaweb

1:20 pm on Jan 2, 2004 (gmt 0)

10+ Year Member



Not sure I asked my question right. What I want to happen is if the value of the item is less than 1 I don't want that data to be shown.

Like wise if the description equals "1" then it shoudn't be displayed.

The recommended code worked once then the got many errors.

}
echo '<td><ul>';
echo '<LI STYLE="list-style-type: circle"> <b>player:</b> ';
echo $book['player'];
echo '<LI STYLE="list-style-type: circle"><b>team:</b> ';
echo $book['team'];
echo '<LI STYLE="list-style-type: circle"><b>current value:</b> ';
echo number_format($book['value'], 2);
echo '<LI STYLE="list-style-type: circle"><b>description:</b> ';
echo $book['description'];
echo '</ul></td></tr></table>';
}
else
echo 'The details of this book cannot be displayed at this time.';
echo '<hr />';
}

coopster

3:09 pm on Jan 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Still not entirely clear to me, but is this what you are after...

if ($book['value'] >= 1 and $book['description']!= '1') {
// echo stuff here...
} else {
// echo error here...
}

Acternaweb

3:37 pm on Jan 2, 2004 (gmt 0)

10+ Year Member



No that didn't work.
If the value of the item is less than 1 I don't want it to be displayed on teh page, butI want it entered in the DB for my records.

so I am sure the code isn't right but in theory

if ($book['value'] >= 1 {
echo '<LI STYLE="list-style-type: circle"><b>current value:</b> ';
echo number_format($book['value'], 2);
}
else
{
don't show value ($book['value'])

if $book['description']!= 'none') {
echo '<LI STYLE="list-style-type: circle"><b>description:</b> ';
echo $book['description'];
}
else
{
Don't show description ($book['description'])

coopster

3:54 pm on Jan 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, it's just those two values that you don't want displayed if the conditions aren't met -- it seemed as though you didn't want anything to be displayed if the conditions weren't met. Thanks for the clarification.

Well, your theory is correct -- and your code is close, just complete the

else
part of your logic and close the statement with and ending brace (}) and test it. You should get the desired results by the looks of it.

travelbuff

4:04 pm on Jan 2, 2004 (gmt 0)

10+ Year Member



Acterna, you don't need the else part of the statement at all:

//check for a value, if there is one, display it.
if ($book['value'] >= 1) {
echo '<LI STYLE="list-style-type: circle"><b>current value:</b> ';
echo number_format($book['value'], 2);
}
//check for a description, if there is one, display it.
if ($book['description']!= 'none') {
echo '<LI STYLE="list-style-type: circle"><b>description:</b> ';
echo $book['description'];
}

will work just fine. When you use an if and no else, php evaluates the if and if it is true, executes the code. If it is false, it just moves the to next set of code.

There are also some other ways to make sure the fields are not empty. For example, I might use:
if ($book['description']!= "" OR NULL)

HTH
Mark