i'm making table reservations scheduling table with PHP and Mysql. i'm stuck on one thing, dont know how to check every cell i must print,which will indicate a reservation, with every column,which will indicate hours. Can anyone give me an idea ? i will get my reservation info from database same as all tables there are in restaurant. It will look something like this:

<table>
  <tbody>
      <th>10:00</th>
      <th>11:00</th>
      <th>12:00</th>
      <th>13:00</th>
        . . .


    <tr>
     <td>Table Nr.1</td>
     <td>check if 10:00 = reservation_time ...</td>
   </tr>
   <tr>
     <td>Table Nr.2</td>
     <td>check if 11:00 = reservation_time ...</td>
   </tr>
  <tbody>
</table>

i will print working time from database using for loop,because every restaurant has it's own working time. Same goes to Table number. i will loop all tables from database.

It should look something like this in the end : 84b6b241634099bfed5f100b38135b5c ![84b6b241634099bfed5f100b38135b5c]

i will give you better presentation of what i need.

echo'
        <table>
            <tbody>
                <th>Table/Hours</th>
    ';
    for($i = $start; $i <= $end ; $i++)
    {
        echo '<th>'.$i.'</th>';
    }

    while($table = mysqli_fetch_assoc($tables))
    {
            echo '<tr>
                     <td>'.$table['ID'].'</td>';

                        for($i = $start_work_hour; $i <= $end_work_hour; $i++)
                        {
                            ..database things....

                            if($reservation_time == $i)
                            {
                                echo '
                                    <td colspan="there goes variable with reservation duration time,say,2h" style="background-color: red">
                                        '.$fname.'
                                        '.$lname.'
                                    </td>
                                ';

                            }
                            else
                            {
                                echo'<td style="background-color: green">FREE</td>';

                            }

                        }
                echo'  </tr>';
    }
    echo '</tbody>
        </table>
        ';

Hi,
to help you solving the problem I need to see the mysql query.

can you post the full php?

$date = $_POST['date'];
$day = $_POST['day'];

    $time_query = "SELECT * FROM time_table";

    $time_result = $conn->query($time_query) or die (mysqli_error($conn));
    $time_row = mysqli_fetch_assoc($time_result);
    $start = $time_row['from_time'];
    $end = $time_row['to_time'];
    $work_interval = $end - $start;

    echo'
        <table>
            <tbody>
                <th>Table/Hours</th>
    ';
    for($i = $start; $i <= $end ; $i++)
    {
        echo '<th>'.$i.'</th>';
    }
    $map_query = "SELECT ID FROM map WHERE rest_id = $admin_id";
    $map_exe = $conn->query($map_query);
    $map = mysqli_fetch_assoc($map_exe);
    $map_id = $map['ID'];

    $table_query="SELECT ID FROM table WHERE map_id = $map_id";
    $table_exe = $conn->query($table_query);

    while($table = mysqli_fetch_assoc($table_exe))
    {
        echo '<tr>
                     <td>' . $table['ID'] . '</td>';

                $rez_query = "SELECT * FROM reservations WHERE rez_data = '".$date."' AND restoran_id = '".$admin_id."' AND table_id = '".$table['ID']."' ORDER BY time ASC";
                $rez_exe = $conn->query($rez_query);
                $rez_row = mysqli_fetch_array($rez_exe);
                $num = mysqli_num_rows($rez_exe);

                if($num == 1)
                {
                    here i dont have problem, i just print everywhere free until it finds one reservation and prints it to table.
                }
                else if ($num >= 2)
                {
                    foreach($conn->query($rez_query) as $key)
                    {
                        $time_from = $key['time_from'];
                        $fname  = $key['fname'];
                        $time_to = $key['time_to'];
                        $interval = $time_to - $time;
                        $time = $start;

                        while($time <= $end)
                        {
                           if($time != $time)
                           {
                               echo '<td>FREE spot</td>';
                           }
                            else
                            {
                                echo '<td colspan="'.$interval.'">'.$fname.'</td>';
                            }
                            $time++;
                        }
                    }
                }
        else
        {
            for($i = $start; $i <= $end ; $i++)
            {
                echo '<td style="background-color: green"></td>';
            }
        }
}
        {
        echo '</tr>';
    }
    echo '</tbody>
        </table>
';

i dont have any trouble when i have only on reservation per day on the same table, same if table isnt in reservation table in database,it just prints for all hours FREE. However, if i have more than on reservations on the same table. i dont know how to put them that it would be like: FREE,FREE,FREE,BUSY,FREE,BUSY,BUSY.

Ok thanks , i just figured it out by my self

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.