0
Good morning!
Next I have a doubt, and I’m not able to reach conclusion.
I’m creating a field called tag where it serves to search for posts related to tag.
In the bank it is completed as follows;
post1 tag: exemplo1,exemplo2
post2 tag: exemplo3,exemplo2
And how should it be out:
tag: exemplo1,exemplo2,exemplo3
If you notice well, it is separated by a comma. Then I explode to separate string. So far so good.
My question is in the string part repeating equal.
$query = mysqli_query($con, "SELECT tag FROM posts WHERE tag NOT IN('') ");
while($row = mysqli_fetch_array($query)){
$explode = explode(',',$row['tag']);
$count = count($explode);
for($i = 0; $i < $count-1; $i++){
echo $explode[$i];
}
}
With this code she’s coming out as follows:
tag: exemplo1,exemplo2,exemplo3,exemplo2
What way to group repeated string?
your idea is to "group" repeated tags or remove?
– Lauro Moraes
Remove, sorry for explanation error.
– Augusto Junior
you can make the following logic: implode > array_unique > explodes
– Lauro Moraes
Don’t take it personally. However, I believe that the ideal would be to totally change the database system, by the code shown apparently is saving several information in a single column, divided by comma, can be considered a violation of 1NF, see this example in the OS of a tag system or which speaks in a generic way of relation n::n.
– Inkeliz