php - How to display MySQL data based on a column field -
i trying make appointment maker potential customers. hours available depend on personal schedules, don't want generic calendar type appointment maker. trying sql db 4 columns [id, made, date, time] following types [int, bit, varchar, varchar].
when selecting data , displaying it, attempting have if statement (php) determine if "made" "00" or "01" - 00 being "appointment available", 01 being "taken".
the output display rows; however, showing rows "appointment available". 1 of rows has "01" in "made" column, , still showing available.
php/sql script after connection:
$sql = "select * $tname"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { if ($row["made"] = '00') { echo "<tr><td>" . $row["id"] . "</td><td>" . 'make appointment' . "</td><td>" . $row["date"] . "</td><td>" . $row["time"] . "</td></tr>"; } elseif ($row["made"] = '01') { echo "<tr><td>" . $row["id"] . "</td><td>" . 'reserved' . "</td><td>" . $row["date"] . "</td><td>" . $row["time"] . "</td></tr>"; } } }
this link output on website:
http://www.jpegchaos.com/appointment.php
i continue re-upload .php attempts see if new information displays.
line 2 should show "reserved" while 1 , 3 should "make appointment"
thank in advance
you need use ==
, not =
when you're checking $row["made"]
. have now, first if
statement always true, never gets elseif
. try this:
$sql = "select * $tname"; $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { if ($row["made"] == '00') { echo "<tr><td>" . $row["id"] . "</td><td>" . 'make appointment' . "</td><td>" . $row["date"] . "</td><td>" . $row["time"] . "</td></tr>"; } elseif ($row["made"] == '01') { echo "<tr><td>" . $row["id"] . "</td><td>" . 'reserved' . "</td><td>" . $row["date"] . "</td><td>" . $row["time"] . "</td></tr>"; } } }