When Iam showing database value from table its just repeating them according to content. First table which is content.
id | category_id | name
-----------------------------
1 | 2 | Jason
2 | 1 | Richard
3 | 2 | John
category table:-
id | name
---------
1 | Manager
2 | Employee
I use query:
$query=mysql_query("SELECT * FROM content");
while($row=mysql_fetch_array($query)){
$data[] = array('id'=> $row['id'],
'category_id' => $row['category_id'],
'name' => $row['name']
);
}
for($i=0;$i<count($data);$i++){
echo $data[$i]['category_id'];
echo $data[$i]['name']."<br/>";
}
OUTPUT:-
2 Jason
2 John
1 Richard
But what i want is:-
OUTPUT:-
2 Jason John
1 Richard
Now when echo out the result it shows me category_id 2 times having category_id=2 with its 2 name but what i want is to show only category_id 1 times and its corresponding 2 name of category_id=2. Please help.
mysql_queryis an obsolete interface and should not be used in new applications as it's being removed in future versions of PHP. A modern replacement like PDO is not hard to learn. If you're new to PHP, a guide like PHP The Right Way can help explain best practices.DISTINCTin yourSELECT- Edit: Wait, there's something else, but I'll have to think about it.