Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can handle it in one of two ways:</p> <p><strong>1.</strong> Use <a href="http://www.mysqlperformanceblog.com/2006/09/04/group_concat-useful-group-by-extension/" rel="nofollow noreferrer">GROUP_CONCAT</a> (as @Dave mentioned in the comment - this is the link: <a href="https://stackoverflow.com/questions/14500748/mysql-php-api-displaying-fetching-multiple-rows-within-rows-from-another-tab/14501190#14501190">MYSQL PHP API - Displaying &amp; Fetching multiple rows within rows from another table</a>). There is a downside however, GROUP_CONCAT has a limit (by default 1024 characters), which you can change with the server variable <code>group_concat_max_len</code>, but you may not have access to do so.</p> <p>This will look pretty much like this:</p> <pre><code>ID | Name | Car Model | Year 1 John BMW, Audi, Renault 1999, 2000, 2003 2 David Mercedes, Ford 2000, 2005 </code></pre> <p>This can get very complicated if there are 30-40 entries per user, and non-readable.</p> <p><strong>2.</strong> The second option is to export it in the following format (not hard to do, you just iterate through all the cars a user has, but write the user only in the first iteration).</p> <hr> <pre><code>ID | Name | Car Model | Year 1 John BMW 1999 Audi 2000 Renault 2003 2 David ..... </code></pre> <p>Here's some sample code (I use plenty of made up methods, that have suggestive names).</p> <pre><code>$csvArray = array(); foreach ($users as $user) { $cars = $user-&gt;getCars(); //random method name. Grabs an array with the cars this user has :) $firstIteration = 1; foreach ($cars as $car) { if ($firstIteration == 1) { // we only set the CSV row the first time we iterate through cars $csvSingle['ID'] = $user-&gt;getId(); // more random method names $csvSingle['Name'] = $user-&gt;getName(); $firstIteration = 0; } $csvSingle['car_model'] = $car-&gt;getCarModel(); $csvSingle['car_year'] = $car-&gt;getCarYear(); $csvArray[] = $csvSingle; // now we add the single row to the big CSV array. } } fputcsv($handle, $csvArray); // $handle is the file you export to </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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