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 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent. This is something i was looking for. Thank you
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.

3 Comments

This does not fix/address the OPs issue.All you are doing is saving all the returned rows into a php array. OP wants to group all data in a comma list by day.
@Sean Yes i want the user names in comma separated list. Thanks
@Sean Combine that with the link I posted and yes it does.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.