I have this following code:
$result = $conn->query($query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . preg_replace('/[^0-9]+/','',$row['total']) . "</td>";
echo "</tr>";
}
What I try to do is if the output is empty, then insert (-) character. Only if there is no value output.
I tried this:
$result = $conn->query($query);
if ($result->num_rows > 0) {
$total = $total ?? "" ?: "-";
while($row = $result->fetch_assoc())
{
echo "<tr>";
echo "<td>" . $total . "</td>";
echo "</tr>";
}
this replaces all outputs with (-). How can I achieve this? please. thank you for your help!
Note that if the result of preg_replace('/[^0-9]+/','',$row['total'])
is empty, then it should insert (-) character.
The inputs are like this:
100.
80.
70.
etc
Expected output would be something like this:
Total
100
90
-
80
70
-
10