2

I use php to get information from stored procedures. From this, i get some column with numbers values and in the same column, sometime it's null or has others characters than numbers. I would like to add specific symbol "$" to the one with numbers only(positive or negative). This is what i've done until now :

    $sql = "financier_gl @DATE1 = '$from', @DATE2 = '$to', @TARGET = '001'";
$result = sqlsrv_query($conn, $sql);
while ($row = sqlsrv_fetch_array($result)) 
{
    //print_r( $row );  // debug code
    if ($row['HTML_CODE'] == 'BOLD(), Green()'){
        $couleur='green';
        $font= 'bold';
    }
    else {
        $couleur='black';
        $font= 'normal';
    } 
    if ($row['Montant'] > 0 ){
        echo '$';
    }
?>
<tbody>
<tr>
<?php echo "<tr style=\"font-weight:$font; color:$couleur;\">"; ?>
<td style="text-transform:lowercase"><?php echo ($row['Nom']); ?></td>
<td><?php echo ($row['Quantite']); ?></td>
<td><?php echo ($row['Montant']); ?></td>
<td><?php echo ($row['D/C']); ?></td>
<td><?php echo ($row['Debit']); ?></td>
<td><?php echo ($row['Credit']); ?></td>

As you can see, that's "Montant" column only that i would to ask $ and get value only. Any ideas? Thank you

2
  • Do you mean, that if $row['Montant'] is a number, you want to echo '$';? Commented Mar 23, 2017 at 15:37
  • Usually it's a number, but the header has title text, and some others row of this column has NULL so doesnt show anything, i don't want to see "$" alone if there's not any numbers. Commented Mar 23, 2017 at 15:40

1 Answer 1

1

If you just want to check if $row['Montant'] is a number and then show a $, you could achieve this by doing something like this:

if (is_numeric($row['Montant'])) {
  echo '$';
}
Sign up to request clarification or add additional context in comments.

3 Comments

@C.Jenkins Glad I could help.. Can you please accept it as the correct answer? :)
Done, in same time, there's any way to convert these number in 9 999.99 than 9999.99 ? just to create space between some number? thx
I think you're looking for something like this? stackoverflow.com/questions/15677094/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.