I'm having trouble trying to search an article by his tag.
In my table in the mysql database, the field tags is like:
tags: "tag1,tag3,tag92,tagasd"
so if i search tag1 it should show the article with that tag.
But it show me this.
I don't know also why it gives me an error in the "data" field because i use it for everything and no error seen.
However i use this query in mysql:
'SELECT * FROM news WHERE tags LIKE "%'.$tag.'%" ORDER BY id DESC'
but i've also used
'SELECT * FROM news WHERE tags REGEXP "[[:<:]]'.$tag.'[[:>:]]" ORDER BY id DESC'
If the tag i'm searching for, is in more than one post, the result search is correct, but if is in only one post, it looks like i've posted over (the picture)
This is the link where you can try (and view):
If you click on the bolder links, you will see correct articles, if you click in the "normale-size" links, you will see something like the picture above.
http://www.qsec.it/Blog/Tags
EDIT:
NEWS CLASS function SearchWithTag(..)
public function SearchWithTag($tag)
{
$db = new Database();
$db->connect();
$db->sql('SELECT * FROM news WHERE tags REGEXP "[[:<:]]'.$tag.'[[:>:]]" ORDER BY id DESC');
$res = $db->getResult();
return $res;
}
TAGS-SEARCH FILE
<?php
$news = new News();
$newsArray = $news->SearchWithTag($categoria);
foreach($newsArray as $arr)
{
?>
<article itemscope itemtype="http://schema.org/Article">
<div class="article-body">
<strong class="contactpage" itemprop="name"><?php echo utf8_encode($arr['titolo']); ?></strong>
<div class="article-data">
<?php echo date('d M Y - H:i', $arr['data']); ?>
<br>
</div>
<div class="article-tag">
<?php
$tag = explode(",",$arr['tags']);
for ($i=0; $i<count($tag);$i++)
{
$cat = str_replace(" ", "", $tag[$i]);
echo "<a href=\"/Blog/Tags/".$cat."\">".$cat."</a>";
echo " <span class=\"separator\">|</span>\n";
}
?>
</div>
</em></strong>
<div class="read-more">
<br>
<b><i class="pull-left"><a href="/Blog/Articoli/<?php echo $arr['titolo_url']; ?>.html">Vai all'articolo..</a></i></b>
<i class="pull-right" itemprop="name"><?php echo $arr['autore']; ?></i>
</div>
</div>
</article>
<br>
<?php
}
?>