警告:mysql_fetch_assoc()期望参数1是资源,在[重复]中给出布尔值

I get this error every time I run the code, I tried going through other similar threads but it didn't help. I am newbie

        $count=3;
            $db = new mysqli ('localhost', 'root', '', 'test');

        $selectSQL='SELECT * FROM coll_mark WHERE univ="'.$_POST['univ'].'" AND '.$brachTxt.'<="'.$_POST['perc'].'"AND '.$brachTxt.'!=""  ORDER BY '.$brachTxt.' DESC LIMIT '.$count;       
        $queryset='';
        $queryset=mysql_query($selectSQL);
        while($row = mysql_fetch_assoc($queryset)) 
        {
        echo('<tr><td id="ColgNames">'.$row['name'].'</td><td align="center">'.$row[$brachTxt].'</td></tr>');
        }

I also checked whether the query structure is correct or not, but the query is working perfectly.

</div>

Try Like this,

$count=3;
$db=mysql_connect('localhost','root','');
if(!$db) {
    die('Could not connect: '.mysql_error());
}
$connection_string=mysql_select_db('test',$db);
$selectSQL='SELECT * FROM coll_mark WHERE univ="'.$_POST['univ'].'" AND '.$brachTxt.'<="'.$_POST['perc'].'"AND '.$brachTxt.'!="" ORDER BY '.$brachTxt.' DESC LIMIT '.$count;       
$queryset=mysql_query($selectSQL);
$num=mysql_num_rows($queryset);
if(0==$num) {
    echo "No record";
    exit;
} else {
    while($row=mysql_fetch_assoc($queryset)) {
        echo('<tr><td id="ColgNames">'.$row['name'].'</td><td align="center">'.$row[$brachTxt].'</td></tr>');
    }
}

Your query most likely fails and hence mysql_query($selectSQL); returns false. A simple if should solve this

$queryset=mysql_query($selectSQL);
if ($queryset) {
    while($row = mysql_fetch_assoc($queryset)) {
    //code
    }
}

Your query is vulnerable to SQL injections! Also keep in mind that mysql_* functions are officially deprecated and hence should not be used in new code. You can use PDO or MySQLi instead. See this answer on SO for more information.

You're declaring a mysqli connection to your database, then use mysql functions.

Try this instead:

$db = mysql_connect('localhost', 'root', '', 'test');

Please note that mysql functions are deprecated as of PHP 5.5.0, and will be removed in the future.

Function mysql_query returns fails on error. Check your SQL query syntax.

btw, syntax error is here... after != operator...

...$brachTxt."!='"  ORDER BY ".$brachTxt."...