1

I am trying to display certain values through GROUP_CONCAT, and GROUP BY, yet only the groups are showing when I test it out, and the other values don't.

function events_calendar() {
     global $connection;
     mysqli_select_db($connection);
     $query = ("SELECT month, GROUP_CONCAT(start_date) as data FROM events GROUP BY month");
     $result = $connection->query($query);
     $str = "";
     while ($row = $result->fetch_assoc()) {
         echo $row['month'];
         echo $row['start_date'];
     }
     return $str;
}

The month values show up, but the start_date values don't.

1 Answer 1

3

The problem is the PHP. Try replacing:

     echo $row['start_date'];

with:

     echo $row['data'];

You need to use the column alias that you assigned in the SELECT.

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

1 Comment

Sorry my bad. I change the alias when answering his other question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.