I’m trying to create a drop down list with information from a database-table in wordpress. Here is my function where I’m getting information from the table and creating a select-form.
function dd_ranalyzes_select(){
global $wpdb;
$table_name = $wpdb->prefix . 'table_name';
$sql = "SELECT * FROM ". $table_name;
$query_resource = mysql_query($sql);
$select = '<select name="ranalyser" ';
$select .= '><option value"">- Velg en -</option>';
while ($ranalyse = mysql_fetch_assoc($query_resource)){
$select .= '<option value='. $ranalyse['id'] .'>'. $ranalyse['name'] .'</option>';
}
// close our select html tag
$select .= '</select>';
// return select
return $select;
}
But when I’m doing this, I’m getting this error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given…
I have tried different stuff but nothing seems to work. Has somebody an idea how to fix this and can give me a hint?
Get rid of the mysqli_ calls and replace them with either mysqli or PDO - the old interface was removed from PHP in December last year and now only works in dead versions of PHP.