$_POST['domain'] is the result of some form’s CHECKBOX with 3 or more values of domain (C,C++,Java,etc.), whose value is now saved in an array '$Domain'. Now, I need to select the tuples from my table which are in the same domain as selected by the user in the CHECKBOX.
I tried using FOR loop, but it gave me a T_FOR unexception
error or something. Now I’m trying it with implode function, its not
giving any query error but not showing any result from the query
either! The PROBLEM is within the IN operator of the query. How
can I solve it?
if(isset($_POST['domain']))
{
$Domain = $_POST['domain'];
$search=$_POST['search'];
$N = count($Domain);
echo("<p>You selected $N domain(s):<br/><br/> ");
for($i=0; $i < $N; $i++)
{
echo($Domain[$i] . "<br/> ");
}
echo("</p>");
$dom_str="'".implode("', '",$Domain)."'";
$query ="SELECT * FROM learner_object WHERE(lo_tag1='$search' || lo_tag2='$search' || lo_tag3='$search') AND
lo_domain IN ( ".$dom_str." ) ";
$result =mysql_query($query)
or die('query failed.'.mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<a href=\" ".$row['lo_url']." \" target=\"_blank\" \">" . $row['lo_name'] . "</a> <br/> ";
echo $row['lo_desc']."<br/><br/>";
}
}
else
echo "<p>You didn't select any Domain.</p><br/>";
Thanks to u all for helping me out. I’ve figured the correct code with all your help.
Query:-