Welcome to WebmasterWorld Guest from 54.167.0.111

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

if - inline statement

     

esso82

7:05 pm on Feb 11, 2012 (gmt 0)



hi guys ... I have this line of code and it just doesn't work for me
$boxcont .= "<td class='list1'>".($routes2show['routes_lube'] == "0") ? 'none' : 'lubed'."</td>";


$routes2show['routes_lube'] is read from database, it is integer and it's equal to 0 (zero) ... the problem is it doesn't give any output..where am I wrong?

esso82

7:23 pm on Feb 11, 2012 (gmt 0)



an error obviously occurred between keyboard and chair :)

$boxcont .= "<td class='list1'>".($routes2show['routes_lube'] == "0" ? 'none' : 'lubed')."</td>";

problem solved ;)

rocknbil

5:40 pm on Feb 13, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



That shouldn't have made any difference. This is a perfectly valid ternary.

$boxcont .= "<td class='list1'>".($routes2show['routes_lube'] == "0") ? 'none' : 'lubed'."</td>";

it's equivalent to this.


if ($routes2show['routes_lube'] == "0") {
$boxcont .= 'none';
}
else {
$boxcont .= 'lubed';
}

I only see two things:

1. The variable may not be SET. This can be tested with isset.
2. You are evaluating an integer as a string by quoting it.

Both together try this:

$boxcont .= "<td class='list1'>".(isset($routes2show['routes_lube']) and ($routes2show['routes_lube'] == 0)) ? 'none' : 'lubed'."</td>";

A better choice would be to check for the row values **before** you get to this part, for example,

$boxcont .= "<td class='list1'>";
if (isset($routes2show['routes_lube']) {
$boxcont .= ($routes2show['routes_lube'] == 0) ? 'none' : 'lubed';
}
else { $boxcont .= 'N/A'; }
$boxcont .= "</td>";

If that "N/A" is not supposed to be there, it will give you a clue something is wrong with the data.

[edited by: rocknbil at 5:44 pm (utc) on Feb 13, 2012]

rocknbil

5:43 pm on Feb 13, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



<oops double-post>
 

Featured Threads

Hot Threads This Week

Hot Threads This Month