php - Check if MySQL Column is empty -
i'm working on page, users post betting picks. in mysql have table bets (id, event, pick, odds, stake, analysis, status, profit).
i check if 'status' empty in mysql, if()
statement not working. if it's empty, should output bets user. code posted in loop.
so wrong if()
statement? , there better way this?
$result = querymysql("select * bets user='$user'"); $row = mysqli_fetch_array($result); if ('' !== $row['status']) { echo "status: " . $status . "</div>" . "published by: " . $user . "<br>" . "pick: " . $pick . "<br>" . "odds: " . $odds . "<br>" . "stake: " . $stake . "<br>" . nl2br($analysis) ; }
if it's empty, should output bets user. code posted in loop.
since checking if it's empty, if
statement should other way round:
if ($row['status'] == '') {
alternatively, can use mysqli_num_rows()
number of rows:
returns number of rows in result set.
$result = querymysql("select * bets user='$user'"); if (mysqli_num_rows($result) > 0) { $row = mysqli_fetch_array($result); echo "status: " . $status . "</div>" . "published by: " . $user . "<br>" . "pick: " . $pick . "<br>" . "odds: " . $odds . "<br>" . "stake: " . $stake . "<br>" . nl2br($analysis) ; }
also, there isn't such function called querymysql()
:
$result = querymysql("select * bets user='$user'");
it should mysqli_query()
. mysqli_query()
, connection parameter needed.
$result = mysqli_query($conn, "select * bets user='$user'");
Comments
Post a Comment