mardi 7 juin 2016

If statement with database values, set different value for each row

if (mysqli_num_rows($result) > 0) {
function duration() {
    if ($row["duration"] == 0) {
        return "Expired";
    } else if ($row["duration"] > -1) {
        return $row["duration"];
    } else {
        return "Unknown Error";
    }
};

    echo '<table>';
    while($row = mysqli_fetch_assoc($result)) {
        timeLeft();
        echo '<tr><td>' . " Left from event: " .  duration() . '</td></tr>';
    }
    echo '</table>';
} else {
    echo "0 results";
};

mysqli_close($conn); 

I am trying to replace 0 with "Expired", but with this code it replaces all tables, Instead of

Left from event: Expired Left from event: 3

I get

Left from event: Expired Left from event: Expired

Aucun commentaire:

Enregistrer un commentaire