Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the best way to do this would be in the PHP code, rather than in SQL.</p> <p>You can achieve this by simply creating an associative array in PHP, using the "text" field as a key, that contains the data you want - and populating it as you pull information from the database.</p> <p>An example:</p> <p>SQL: <code>SELECT * FROM myTable</code></p> <p>PHP Code:</p> <pre><code>&lt;?php // Connect to MySQL database $result = mysql_query($sql_query_noted_above); $stringsInfo = array(); while ($row = mysql_fetch_assoc($result)) { if (!isset($stringsInfo[$row['text']])) { $stringsInfo[$row['text']] = array('types' =&gt; array(), 'idAccounts' =&gt; array()); } $stringsInfo[$row['text']]['types'][] = $row['type']; $stringsInfo[$row['text']]['idAccounts'][] = $row['idAccount']; } ?&gt; </code></pre> <p>This will give you an array as follows:</p> <pre><code>'myTextString' =&gt; 'types' =&gt; 'type1', 'type2', 'type3' 'idAccounts' =&gt; 'account1', 'account2' 'anotherTextString' =&gt; 'types' =&gt; 'type2', 'type4' 'idAccounts' =&gt; 'account2', 'account3' </code></pre> <p>and so on.</p> <p>I hope that's helpful.</p> <p>EDIT: Poster asked for help with display.</p> <pre><code>&lt;?php foreach ($stringsInfo as $string =&gt; $info) { echo $string . '&lt;br /&gt;'; echo 'Types: ' . implode(', ', $info['types']); // This will echo each type separated by a comma echo '&lt;br /&gt;'; echo 'ID Accounts: ' . implode(', ', $info['idAccounts']); } </code></pre> <p>/* Alternatively, you can loop each array contained in $info if you need more control */</p> <p> <pre><code>foreach ($stringsInfo as $string =&gt; $info) { echo $string . '&lt;br /&gt;'; echo 'Types: '; foreach ($info['types'] as $type) { echo $type . ' - '; } echo '&lt;br /&gt;'; echo 'ID Accounts: ' foreach ($info['idAccounts'] as $idAccount) { echo $idAccount . ' - '; } } </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.
 

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