Weird Display

I have the following statement in my code:

$satt = ( $att = 0 ) ? ‘No’ : ‘Yes’

$satt

It does not display the correct Yes/No and on the screen I get this = ( 0 = 0 ) ? ‘No’ : ‘Yes’ above my table.

What do I have wrong?

Thanks

Post that entire snippet, your abbreviation can have errors that are not in the actual file.

Currently, $satt will always equal ‘No’, because you are assigning a 0 value to $att. I am going to guess that, that statement is in a display variable…

Code to generate with Yes or No:

$result = $conn->query("select a.name, b.week from players a, dates b where a.playersid = '$player' and b.dateid = '$date'");

while($row = mysqli_fetch_array($result)) {
    echo "<tr>
        <td align='center'>" . $row['name']    . "</td>
        <td align='center'>" . $row['week']    . "</td>";
    echo "$satt = ( $att = 0 ) ? 'No' : 'Yes'";
    echo "<td align='center'><span>$satt</span></td>";
    echo "  <td align='center'>$pts</td>
            <td align='center'>$ $amt</td>
            <td align='center'>$ $high</td>
            <td align='center'>$ $fty</td>
    </tr>";

	}

Just as I said,

[php] echo “$satt = ( $att = 0 ) ? ‘No’ : ‘Yes’”;
echo “

$satt”;[/php]

Compared to,
[php] $satt = $att == 0 ? ‘No’ : ‘Yes’;
echo “

$satt”;[/php]

This is also a bit easier to read:
[php]while($row = mysqli_fetch_array($result)) {
$satt = $att == 0 ? ‘No’ : ‘Yes’;
echo "


{$row[‘name’]}
{$row[‘week’]}
$satt
$pts
$ $amt
$ $high
$ $fty
";
}[/php]

You should also look into the PHP function money_format(). It formats numbers to local currency in linux OS’s.

I recommend not echoing code or markup. If you write it normally then your IDE will syntax highlight it properly and it’s much easier to see mistakes.

[php] $result = $conn->query(“select a.name, b.week from players a, dates b where a.playersid = ‘$player’ and b.dateid = ‘$date’”);

while($row = mysqli_fetch_array($result)) {
echo "


" . $row[‘name’] . "
" . $row[‘week’] . “”;
echo “$satt = ( $att = 0 ) ? ‘No’ : ‘Yes’”; // here you echo the php code as plain text
echo “$satt”;
echo " $pts
$ $amt
$ $high
$ $fty
";
}[/php]

[php]$result = $conn->query(“select a.name, b.week from players a, dates b where a.playersid = ‘$player’ and b.dateid = ‘$date’”);

while($row = mysqli_fetch_array($result)): ?>

<?= $row['name'] ?> <?= $row['week'] ?>"; <?= $att == 0 ? 'No' : 'Yes' ?> <?= $pts ?> <?= $amt ?> <?= $high ?> <?= $fty ?> <?php endwhile;[/php]

I would actually toss it into a model use a template engine to parse it… But I learned the old fashion way before the new way.

Thank you.

In reference to this;
“I won’t help if you’re using mysql_* functions | You should use PDO | MariaDB | Netbeans IDE | About me.”

Never hears of PDO, MariaDB, About ME.

I just downloaded Komodo IDE and Netbeans IDE.

Don’t like Komodo, going to try Netbeans tomorrow.

Thanks

um, that is a signature. That’s it. It shows for every post they make.

OK, anyway I like Netbeans IDE.

Thanks for the info.

Sponsor our Newsletter | Privacy Policy | Terms of Service