0

I am trying to make an appointment maker for potential customers. The hours that are available will depend greatly on personal schedules, so I don't want a generic calendar type appointment maker. What I was trying was an SQL DB with 4 columns [ID, Made, Date, Time] with the following types [INT, BIT, VARCHAR, VARCHAR].

When SELECTing my data and displaying it, I am attempting to have an IF statement (PHP) determine if "Made" is "00" or "01" - 00 being "appointment available", 01 being "taken".

The output does display all the rows; however, it is showing all the rows as "appointment available". One of my rows has "01" in the "Made" column, and it is still showing as available.

PHP/SQL Script after connection:

$sql = "SELECT * FROM $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 An 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 is the link to the output on the website:

http://www.jpegchaos.com/appointment.php

I will continue to re-upload the .php with any attempts to see if new information displays.

Line 2 should show "Reserved" while 1 and 3 should be "Make an Appointment"

Thank you in advance

1 Answer 1

2

You need to use ==, not = when you're checking the $row["Made"]. As you have it now, the first if statement is always true, so it never gets to the elseif. Try this:

$sql = "SELECT * FROM $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 An 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>";
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Of course it had to be something simple like that. Thank you so much.
No problem, happens to everyone. :)
i'll approve as soon as it lets me.

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.