i got an warning like this “mysql_fetch_assoc() expects parameter 1 to be resource”, how can i fix this?
Thanks!
global $wpdb;
$con=mysqli_connect("localhost","root","");
mysqli_select_db('search');
$search = mysql_real_escape_string(trim($_POST['searchquery']));
$sqlCommand = $wpdb->get_results("SELECT * FROM `wp_doctors` WHERE `name` LIKE '%searchquery%'");
while($row = mysql_fetch_assoc($sqlCommand)){
$id = $row['id'];
$name = $row['name'];
$spec = $row['spec'];
echo "Nume: $name<br />Specializare: $spec";
}
There is no need for this ,
$row = mysql_fetch_assoc($sqlCommand)
$wpdb->get_results already did the job just
var_dump $sqlCommand
and you will see the mistake.Mulitple row results can be pulled from the database with get_results. The function returns the entire query result as an array,
So you could make this change in your code: