[wp-hackers] help with custom query results

Brian Fidler fidler.brian at gmail.com
Thu Jun 3 00:41:33 UTC 2010


I'm working with the following custom query:

$querystr = "
SELECT wp_rg_lead.date_created,
wp_rg_lead_detail.lead_id,
wp_rg_lead_detail.form_id,
wp_rg_lead_detail.field_number,
group_concat(wp_rg_lead_detail.value ORDER BY
wp_rg_lead_detail.field_number) AS resultsrow,
wp_rg_lead.post_id,
wp_rg_lead.source_url,
wp_rg_lead.user_agent
FROM wp_rg_lead_detail INNER JOIN wp_rg_lead ON wp_rg_lead_detail.lead_id =
wp_rg_lead.id
WHERE ( wp_rg_lead_detail.form_id = '3' )
GROUP BY wp_rg_lead_detail.lead_id
";

$results = $wpdb->get_results($querystr, OBJECT);
$resultscount = count($results);

______________________________________________

The item that returns as "resultsrow" needs to be exploded into an array
with a comma delimiter but I'm having difficulties doing so. If
$resultscount = 4, what is the best way to iterate through "resultsrow" so
that I end up with the following that I can then place in my layout?:

$result1[0]
$result1[1]
$result1[2]
$result1[3]

$result2[0]
$result2[1]
$result2[2]
$result2[3]

$result3[0]
$result3[1]
$result3[2]
$result3[3]

$result4[0]
$result4[1]
$result4[2]
$result4[3]

My final layout needs to be a number of rows with the fields pulled from
"resultsrow".

thanks,
brian


More information about the wp-hackers mailing list