0

Hello this table pulls data from a database.

<h2>Weekly appointment list</h2>

      <table class="table table-bordered table-hover">
        <thead>

          <tr>
            <th>Week Day</th>
            <th>Customers</th>
            <th>Selected service</th>
            <th>Time</th>
          </tr>
        </thead>

        <tbody>
          <tr>
            <td>Monday</td>


                <?php 
                    $date = date('Y-m-d', strtotime("this Monday"));
                    $sql = "SELECT * FROM appointment WHERE weekday = '$date'";
                    $query = mysqli_query($db, $sql);
                    $numRows = mysqli_num_rows($query);

                    if ($numRows > 0) {
                    while ($row = mysqli_fetch_array($query)) { ?>

                        <td><?php echo $row['user_name'] ?></td>
                        <td><?php echo $row['service'] ?></td>
                        <td><?php echo $row['time'] ?></td>

                    <?php } 
                        }
                     ?>
            </tr>

        </tbody>

But the problem is when i have two users from echo $row['user_name'] //user x, user y the table rows break and show something like this: image link. See the the table row is broken. I want to show this way:expected table structure. All customers are shown on the particular day row in customers column. How to fix my code or the way of representation. Thanks in advance.

2 Answers2

2

change your sql query to group concat username,service and time.

 $sql ="SELECT group_concat(user_name) as user_name,group_concat(service) as service ,group_concat(time) as time FROM appointment WHERE weekday = '$date'";

This query will return one row with all the user and service information in one row.

akr
  • 739
  • 4
  • 15
0

you want to combine something like this

With something like this:

$res  = mysql_query(/**/);
$rows = array();
while($row = mysql_fetch_assoc($res)){
  array_push($rows, $row);
}

Let me know if you struggle.

Community
  • 1
  • 1
n00bstacker
  • 323
  • 2
  • 6
  • 23