Here's my issue. I have three tables I'd like to query - states, points, and state_points.
States contains stateid, and name. Points: pointid, pointlat, pointlng. State_points: Stateid, Pointid.
I need to build an array which displays the States, and then the corresponding points. To do this I figured the best way would be something like this tutorial: http://www.bitsofphp.com/avoid-executing-mysql-queries-within-loops/
Query all the states, make an array using the stateids as the arrayids.
Then select the lat, lng, and stateid from the points and state_points table.
Add the points (lat and lng) to the array, using the stateid selected in the 2nd query as the array id
global $wpdb;
$states = $wpdb->query("SELECT * from wp_states");
echo $states;
while ($state = mysql_fetch_array($states)) {
$arrayState[$state['stateid']]=$state;
}
$points = $wpdb->query("SELECT wp_state_points.statepointid, wp_state_points.stateid, wp_state_points.pointid, wp_points.pointid, wp_points.lat, wp_points.lng FROM wp_state_points, wp_points WHERE wp_state_points.pointid = wp_points.pointid");
while ($point = mysql_fetch_array($points)) {
$arrayState[$point['stateid']]['points'][]=$point;
}
foreach ($arrayState as $astate) {
echo $astate['name'];
foreach ($astate['points'] as $apoint) {
echo $apoint['lat'];
}
}
Something like this however I receive "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in..."
I know that my query is returning data (at least the first one). I think that wordpress query simply doesn't support this.
I could use get_results to return an array. But to make this work the arrayids have to be the same as the stateids
What can I do to make this work?
Thanks
mysql_functions directly, continue using thewpdbglobal. codex.wordpress.org/Class_Reference/wpdb