Note that there are some explanatory texts on larger screens.

plurals
  1. POmultidimensional array output. Help me extract and loop through this mess please
    text
    copied!<p>So I have this awesome MySQL query that's returning me an awesome array ></p> <pre><code>$join_sql = "SELECT $detail_table.`lead_id`, $detail_table.`field_number`, $detail_table.`value` FROM $lead_table JOIN $detail_table ON $lead_table.`id` = $detail_table.`lead_id` WHERE $lead_table.`date_created` BETWEEN '2012-03-18 00:00:00' AND '2012-03-19 23:59:59'"; $join_query = $wpdb-&gt;get_results($join_sql, ARRAY_A); </code></pre> <p>This is returning a (in my opinion) complex associate array that looks like this - <a href="http://pastebin.com/kpXrK9Ra" rel="nofollow">http://pastebin.com/kpXrK9Ra</a></p> <p>(I don't understand data storage methodology but this seems overly complicated to me to have each bit of data in it's own dimensional array rather than just a row of data for each record. But anyway, this is what I have to deal with.)</p> <p>So here's a small sample of what I need to get to ></p> <pre><code>[23] =&gt; Array ( [lead_id] =&gt; 3 [field_number] =&gt; 6.3 [value] =&gt; Jane ) </code></pre> <p>So the key that represents a "record" in my mind is the [lead_id]. I need to be able to create a var $first_name. My resultset may have 50 unique [lead_id} but for the first name, the [field_number] will always be '6.3'. </p> <p>So how do I loop through the pastebin and create vars for each of the elements so that all the [lead_id] with matching numbers outputs something like-</p> <pre><code>$first_name, $last_name, $whatev, $foo, $bar, $etc </code></pre> <p>I'm not even sure if this makes sense... :\</p> <p>EDIT: What I'm trying to do is access the 'field_number' which corresponds to what the field is, ie: a first name, second name, etc. and the corresponding 'value' and output all of those in a particular order that matches the 'lead_id'. So all lead_id's of [2] would be output into a line of the CSV, and then the next lead_id, etc.</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload