I have data saved in tag base in a format like this PHP,HTML,CSS,JS
and when i select all from my data base i explode it using php to give each one design.
My problem is when i have multiple tag name stored in database in a different row and i want to show tag only once how do i do it?
Example
My data base
id | tag | name |
----|------------------|--------|---
1 | PHP,HTML,JS,SQL | file |
2 | CSS,HTML,JQUERY | code |
3 | AJAX,PYTHON,HTML | script |
Now when i select id,tag
it will return this
1 PHP,HTML,JS,SQL
2 CSS,HTML,JQUERY
3 AJAX,PYTHON,HTML
And when i explode it using bellow php i get the tags added hyper reference tag in each
<?php
$exploded_string_tag = '';
if(!empty($tagstring)){
$GetThestring = $tagstring;
$arrayOfTags = explode(',', $GetThestring);
foreach($arrayOfTags as $LinkTageKey) {
$trimstr = preg_replace('/\s+/', '', $url.$LinkTageKey);
$exploded_string_tag .= '<a class="tags-s label-primary" href="'.$trimstr.'">'.$LinkTageKey.'</a>';
}
?>
So how do i make this to show one tag if it is more than 2 that was selected from table? Make it look like this using babe while exploding it example i have HTML
in all and i want to show only one
Raw data | Exploded | What I want
------------------------|-------------|-----------------
1 PHP,HTML,JS,SQL | PHP | PHP
2 CSS,HTML,JQUERY | HTML | HTML
3 AJAX,PYTHON,HTML | JS | JS
| SQL | SQL
| CSS | CSS
| HTML | JQUERY
| JQUERY | AJAX
| AJAX | PYTHON
| PYTHON |
| HTML |
$new_array = array_unique($exploded_array);
Try this :
$array = array(PHP,HTML,JS,SQL,CSS,HTML,JQUERY,AJAX,PYTHON,HTML);
Now use this :
$unique_array = array_unique($array);
Hope it hepls !!!