I have the following query using ‘$wpdb->get_results’, I have an issue where the join of the second row of results changes the default ID (primary id in $shipping_table) from an ID of 2 to a value of 1.
If I set the column names instead of a wilcard it works. But I still want to know why using a wilcard is causing this behaviour. Any help appreciated.
Query
$items = $wpdb->get_results("
SELECT *
FROM `$shipping_table` s
LEFT JOIN `$shipping_type_table` st ON s.shipping_type_id = st.id
WHERE s.shipping_active = 1
ORDER BY s.shipping_order ASC;
");
Results (PHP dump)
array (size=2)
0 =>
object(stdClass)[1368]
public 'ID' => string '1' (length=1)
public 'shipping_name' => string 'UK' (length=2)
public 'shipping_amount' => string '10.000' (length=6)
public 'shipping_type_id' => string '1' (length=1)
public 'shipping_order' => string '1' (length=1)
public 'shipping_package' => string '1' (length=1)
public 'shipping_active' => string '1' (length=1)
public 'shipping_type_name' => string 'fixed' (length=5)
public 'shipping_type_active' => string '1' (length=1)
1 =>
object(stdClass)[1369]
public 'ID' => string '1' (length=1)
public 'shipping_name' => string 'USA' (length=3)
public 'shipping_amount' => string '15.000' (length=6)
public 'shipping_type_id' => string '1' (length=1)
public 'shipping_order' => string '2' (length=1)
public 'shipping_package' => string '0' (length=1)
public 'shipping_active' => string '1' (length=1)
public 'shipping_type_name' => string 'fixed' (length=5)
public 'shipping_type_active' => string '1' (length=1)
if I run the same query in phpMyAdmin it returns the correct response (see below)
screenshot of query in phpmyadmin
thanks
Nick