trying to convert a fuction that uses mysqli to use the wpdb class
-
Hi guys i got a bit of a problem, I’m trying to make a set of function to pull items from an added table and build an interface to sort products with. the problem is that i can’t figure out how to get the wpdb class to work like mysqli. i wrote it with mysqli and it worked till i updated to 2.8.2 and i figure useing mysql over wordpress is a bit of a hack. anyway here are my two functions that talk (or at least use to) to the database.
function get_product_manufacturers($var=NULL) { global $wpdb; $query = 'SELECT * FROM akt_products ORDER BY id asc'; $results = $wpdb->query($query, 'OBJECT'); if($results->num_rows) { while($row = $results->fetch_object()) { $manufacturers_all[$row->id] = stripcslashes(htmlspecialchars_decode($row->manufacturer)); } $manufacturers = array_unique($manufacturers_all); if($var=='all') { return $manufacturers_all; }else{ return $manufacturers; } } } function get_product_categories($var=NULL) { //get the catergories global $wpdb; $query = 'SELECT * FROM akt_products ORDER BY id asc'; $results = $wpdb->query($query); if($results->num_rows) { while($row = $results->fetch_object()) { $categories_all[$row->id] = stripcslashes(htmlspecialchars_decode($row->category)); } } //build the array - NOT UNIQUE! $manufacturers_all = get_product_manufacturers('all'); if($var==NULL): break; elseif($var=='all'): $categories = array_unique($categories_all); else: $i=0; foreach($manufacturers_all as $key => $manufacturer) { if($manufacturer != $var) {} elseif($manufacturer == $var) { $categories_current[$i] = $categories_all[$key]; } $i++; } $categories = array_unique($categories_current); endif; return $categories; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘trying to convert a fuction that uses mysqli to use the wpdb class’ is closed to new replies.