I made the joke database into an event database, and was wanting to format the output in the include file so the event dates would appear under the event and location.
Some searching indicated I might have to make a multidimensional array to accomplish this. Setting up my code to try that, I tried this and it kind of works.
I am still getting more blockquotes and paragraphs than I need, but I never expected the include file would see the concatenated array as separate entities.
<p>Here are all the shows in the database:</p>
<?php foreach ($event as $event): ?>
<blockquote>
<p><?php echo htmlspecialchars($event, ENT_QUOTES, 'UTF-8'); ?></p>
</blockquote>
<?php endforeach; ?>
html source snip
<p>Here are all the shows in the database:</p>
<blockquote>
<p>* The Great Alaska Sportsman Show - Sullivan Arena</p>
</blockquote>
<blockquote>
<p> 2010-04-08 through 2010-04-11</p>
</blockquote>
<blockquote>
<p>* Comfish Alaska - Kodiak Convention Center</p>
</blockquote>
<blockquote>
<p> 2010-04-15 through 2010-04-17</p>
</blockquote>
<blockquote>
<p>* Alaska Women's Show - Sullivan Arena</p>
</blockquote>
<blockquote>
<p> 2010-04-23 through 2010-04-25</p>
</blockquote>
<p>Here are all the shows in the database:</p>
<?php foreach ($event as $event): ?>
<blockquote>
<p><?php echo htmlspecialchars($event['sholoc'], ENT_QUOTES, 'UTF-8'); ?><br/>
<?php echo $event['dates']; ?>
</p>
</blockquote>
<?php endforeach; ?>
That works, and shows a multidimensional array is not needed.
That IS a multidimensional array. You created an array, $event, where each value in the array is another array having two values.
You can do it with zero extra arrays if you want, just loop through the result set as needed. You can always reset the row pointer in the result set back to 0 with mysql_data_seek
Just to share what worked for me - and so anyone searching on GROUP_CONCAT, explode and array_combine might find one way that works
the query:
$result = mysqli_query($link, 'SELECT events.event, events.location,
DATE_FORMAT(events.startdate, "%a %b %e %Y") as startdate,
DATE_FORMAT(events.enddate, "%a %b %e %Y") as enddate,
GROUP_CONCAT(filestore.id) as file_id,
GROUP_CONCAT(filestore.description) as filedesc
FROM events
LEFT JOIN filestore ON events.id = filestore.event_id
GROUP BY events.id ORDER BY events.startdate ASC
LIMIT 0 , 30 ');