Note that there are some explanatory texts on larger screens.

plurals
  1. POmulti dimensional array from a joined mysql query
    primarykey
    data
    text
    <p>So this has been kicking my butt a bit. A little explanation is that I have 2 tables - equipment and ehours. Essentially, the equipment remains static and is transferred to a project and then is tracked on a daily basis on it's usage. <code>equipment.eid</code> is the unique identifier for the equipment and is then used in each ehours entry.</p> <p>Following is the query I am using to create my ouput. The output I'm getting is sorted correctly, but can't figure out how to output properly. </p> <pre><code>SELECT e.cid, e.eid, h.pid, h.hdate, e.eqid, e.name, e.make, e.model, h.hours, e.uid FROM equipment e LEFT JOIN ehours h on h.eid = e.eid AND MONTH(h.hdate) = $data[month] AND YEAR(h.hdate) = $data[year] ORDER BY cid ASC, eid ASC, pid ASC, hdate ASC </code></pre> <p>The problem I'm having is that in a given month a piece of equipment may be on 2 separate projects. The query shows the following...</p> <pre><code>cid | eid | pid | hdate | eqid | name | make | model | hours | uid 4 | 55 | 1 | 2012-11-01 | E8 | Forklift | Clark CGP25 | | 5 | 1 4 | 55 | 1 | 2012-11-07 | E8 | Forklift | Clark CGP25 | | 5 | 1 4 | 55 | 1 | 2012-11-10 | E8 | Forklift | Clark CGP25 | | 2 | 1 4 | 55 | 1 | 2012-11-13 | E8 | Forklift | Clark CGP25 | | 3 | 1 4 | 55 | 4 | 2012-11-13 | E8 | Forklift | Clark CGP25 | | 2 | 1 </code></pre> <p>The output needs to have a 2nd dimension of the dates which will be output in the proper days for the month. The final display will show all dates of the month. For instance, the first <code>eid</code> will output on one line with the <code>pid</code> of 1 and have the <code>hours</code> in the proper day of the month. It will then have a line afterwards with the same piece of equipment but having a <code>pid</code> of 4.</p> <p>So, anyway I'm needing to somehow create the dates into a 2nd dimension of the array that I can walk through as I output each row. Or maybe a 3rd dimension to catch the hours that are associated with each date? I've looked at several php methods to attempt this, but have been unsuccessful so far. Any help is greatly appreciated. Wow - this turned into a novel.</p> <p><strong>Edited:</strong></p> <p>The following is what output should be...</p> <pre><code>pid | eqid | name | make | 11-01 | 11-02 | ... | 11-07 | ... | 11-10 | ... | 11-13 1 | E8 | Forklift | Clark CGP25 | 5 | 0 | ... | 5 | ... | 2 | ... | 3 4 | E8 | Forklift | Clark CGP25 | 0 | 0 | ... | 0 | ... | 0 | ... | 2 </code></pre> <p>Would also have to account for a NULL value for <code>pid</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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