DETAIL ABOUT MY GOAL:
So I made a little box on the side of my site that lets choose what we want to see, but I'm having trouble with that box. It sends the information in Get, basically there is nothing in the Get so the site displays all the images regardless of the tag it has then once we have chosen a tag with the small box, that send the tag in Get then reload the page which is now supposed to display only the images which have the chosen tag. When I echo my var it works, I can see the right word, but It seems to have a problem with the select statement.
ACTUAL RESULT:
Actually, it simply shows nothing, except the echo of my var to see if it works,, my code isn't displaying anything. Yes in my DB there are items with the tag i'm looking for because when I display every images, so without wanting only one tag I can see the tag and they are there.
WHAT I'VE ALREADY READ TO TRY TO FIX THE PROBLEM:
Strange behavior with SELECT WHERE A="$var" SQL
PHP SQL where statement with loop variable
PHP SQL and use of 'WHERE' with a variable
PHP & SQL WHERE (changing variable)
SQL query with variable "Where"
WHAT I'VE ALREADY TRIED:
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = $tag ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = '$tag' ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ' . $tag . ' ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = :$tag ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ':$tag' ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = "$tag" ORDER BY pic_id DESC";
'SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ' . $tag . ' ORDER BY pic_id DESC';
'SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = &tag ORDER BY pic_id DESC';
'SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = &$tag ORDER BY pic_id DESC';
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ". $tag . " ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ($tag) ORDER BY pic_id DESC";
"SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = {$tag} ORDER BY pic_id DESC";
I've even tried with the $_GET instead of the my var
HERE IS THE MINIMUM CODE SHOWING HOW IT GET AND WHERE IT SELECT:
$tag = $_GET['tagChoosen'];
if(isset($_GET["tagChoosen"]))
{
echo "<br/> $tag";
$result = "SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ':$tag' ORDER BY pic_id DESC";
$results = $pdo->query($result);
}
else
{
$result = "SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid ORDER BY pic_id DESC";
$results = $pdo->query($result);
}
while ($data = $results->fetch())
{
$resultat = "SELECT username FROM tblClients WHERE client_id = ".$data['client_id'];
$resultats = $pdo->query($resultat);
while ($datas = $resultats->fetch())
{
$clientUsername = $datas['username'];
}
echo "
<div class='imgContainer'>
<div class='img'>
<img class='theImg' src='{$data['pic_path']}' onclick='window.open(this.src)'>
<div id='infoContainer'>
<div id='sousInfoContainer1'>
<div id='info1'>
<div class='info'>
<p>Date de publication: {$data['date_posted']}</p>
</div>
</div>
<div id='info2'>
<div class='info'>
<p>Tag: {$data['tag']}</p>
</div>
</div>
</div>
<div id='sousInfoContainer1'>
<div id='info3'>
<div class='info'>
<p>Publieur: {$clientUsername}</p>
</div>
</div>
</div>
</div>
<a href='{$data['pic_path']}' download='{$data['pic_path']}'>
<button class='btn'><i class='fa fa-download' alt=''></i> Télécharger</button>
</a>
<hr class='botrow'>
</div>
</div>
";
}
?>
</div>
<div id="rightContainer">
<form id='CatChoice' action='' method='get'>
<label><br/>Choisissez la catégorie que vous voulez voir</label>
<select name='tagChoosen'>
<option value='Drôle'>Drôle</option>
<option value='Dark'>Dark</option>
<option value='Informatique'>Informatique</option>
<option value='Programmation'>Programmation</option>
<option value='Gaming'>Gaming</option>
<option value='Animaux'>Animaux</option>
<option value='Film'>Film</option>
<option value='Série'>Série</option>
<option value='18+'>18+</option>
<option value='École'>École</option>
<option value='Travail'>Travail</option>
<option value='Soviet'>Soviet</option>
</select>
<input type='submit' value='Choisir' name='submit'>
</form>
</div>
</div>
I tried too, to put the entire while in both of if and else, but it doesn't work
I don't really like to use stackoverflow because I always get ban from posting question, cause people think my questions are useless, but I'm just learning, no question is useless if she helps someone. But i'm really stuck. I've been stuck there for now 3 days.
$tag"; $result = "SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid WHERE tag = ($tag) ORDER BY pic_id DESC"; } else { $result = "SELECT pic_id, pic_path, date_posted, tag, client_id FROM tblMemeovid ORDER BY pic_id DESC"; } $results = $pdo->query($result); while ($data = $results->fetch()) { – Dolotboy Sep 08 '20 at 13:07