MySqli query inside a function
-
Hi Guys
I have a function where, inside it I need to connect to a table and display results. The query woks fine outside of the function, but when i run it inside i get this error.
Notice: Undefined variable: wpdb in /pathtopage/common.php on line 301 Fatal error: Call to a member function get_results() on a non-object in /path to page/common.php on line 301
Here is the MySqlI query inside the function
` $options = array();
$res= $wpdb->get_results (“SELECT County FROM counties”);
$value=””;
$label=”Please select a county”;
$options[] = array(‘label’ => $label, ‘value’ => $value);
foreach ($res as $row) {
$sC=$row->ID;
$res1=$wpdb->get_results (“select County from wedding_shows where County=’$sC'”);
$res1_cnt->mysqli_num_rows($res1);
if ($res1_cnt<1) {
} else {
$options[] = array(‘label’ => $row->County, ‘value’ => $row->ID);
}
}$dropdown = $form->getElement(‘iphorm_7_1’);
if ($dropdown instanceof iPhorm_Element_Select) {
$dropdown->setOptions($options);
}
}`Any ideas please
Many thanks
P
- The topic ‘MySqli query inside a function’ is closed to new replies.