Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter Posts depending ID of categorie with PHP
    primarykey
    data
    text
    <p>I have a small task where I have a mysql table "blog".It contains a column "ID_CAT". Each field of ID_CAT contains diiferent values of category for one single article like "22,44,33,55" . I want to filter the posts of blog depending on the category choosing . i pass the ID_CAT choosing into URL and GET methode in the included page like that</p> <pre><code>&lt;a class="rotated_link" href="?cat='.$categorie-&gt;getIDCategorie().'"&gt;'.$categorie-&gt;getNomCategorie().'&lt;/a&gt; </code></pre> <p>then the page included like that</p> <pre><code>$id_categorie = $_GET["cat"]; if (isset($id_categorie)) { foreach(Article::getAllArticlebycategorie($id_categorie) as $all){ $article= new Article($all-&gt;ID_BLOG); $img=Image::getImageByArticle($article-&gt;getIDarticle()); $tblCat=explode(',',$article-&gt;getIDCategorie()); echo '&lt;li class="li_blog_post"&gt;'; echo'&lt;img class="img_post_mini" src="img/file/'.$img.'" style="width:100%; height:150px; border:1PX solid #9D9D9D;" /&gt;'; echo'&lt;span class="post_title0"&gt;'.$article-&gt;getTitlearticle().'&lt;/span&gt;'; echo'&lt;span class="tag_post"&gt;&lt;img src="img/tag.png" style="width:16px; height:16px;"/&gt;'; foreach($tblCat as $catt){ $categoriea = new Categorie($catt); echo '&lt;a class="tag_lable" href=""&gt;'.$categoriea-&gt;getNomCategorie().'&lt;/a&gt; &lt;/span&gt;'; } echo'&lt;p class="post_prev"&gt;'.substr($article-&gt;getArticle(), 0, 410).'&amp;nbsp;...&lt;/p&gt;'; echo'&lt;span class="date"&gt;le&amp;nbsp;'.$article-&gt;getDatearticle().'&lt;/span&gt; &lt;span class="view_more"&gt;&lt;a class="test" href="?article='.$article-&gt;getIDarticle().'"&gt;voire les détails&lt;/a&gt;&lt;/span&gt;'; echo '&lt;/li&gt;'; } } </code></pre> <p>the probleme is when i choose for example ID_CAT=4 , the function getAllArticlebycategorie returne the posts only if the number 4 is the first value in column ID_CAT (4,33,50)-> selected (3,4,10)-> not selected . the function :</p> <pre><code>public static function getAllArticlebycategorie($id_categorie){ global $db; $req = $db-&gt;prepare('SELECT * FROM blog WHERE ID_CAT='.$id_categorie); $req-&gt;execute(); return $req-&gt;fetchAll(PDO::FETCH_OBJ); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload