I have this in php
$comment = array;
while($row = mysql_fetch_array($sqlExec, MYSQL_ASSOC)){
$comment[$row['name']] = $row['comment'];
}
echo json_encode($comment);
Having these results
{"John":"Yo","Dan":"Hello","May":"Bye"}
The problem is I actually have two comments(Zup,Yo) for John, but as you can see, it only displays the last comment of John which is "Yo". So I wanted the results of John to be
{"John":["Yo","Sup"]}
^ is this possible?
How can I do that? Im sorry still having a hard time dealing with JSON. Thanks
This is actually my full code
while($row = mysql_fetch_array($sqlExec, MYSQL_ASSOC)){
$comment[$row['name']] = $row['comment'];
$sql_dup = "SELECT name, COUNT(name) AS dup_count
FROM comment
GROUP BY name
HAVING (COUNT(name) > 1)
";
$sqlExec_dup = mysql_query($sql_dup, $connection);
$row_dup = mysql_fetch_array($sqlExec_dup, MYSQL_ASSOC);
if($row['name'] = $row_dup['name']){
$sql_dup2 = "SELECT * FROM comment WHERE name = '{$row['name']}'";
$sqlExec_dup2 = mysql_query($sql_dup2, $connection);
while($row_dup2 = mysql_fetch_array($sqlExec_dup2, MYSQL_ASSOC)){
$x += 1;
if($x <= $row_dup['dup_count']){
$comment[$row['name']][] = $row_dup2['comment'];
}
}
}
}
If the name has a duplicate, meaning it has more than one comment, still cant get my desired results.