Note that there are some explanatory texts on larger screens.

plurals
  1. POEstablishing an array from foreach loop
    text
    copied!<p>I have a form which allows a user to register for multiple events. These are listed in a form with checkboxes (all named <code>registrations[]</code> with the event ID as the value) and are submitted as an array.</p> <p>A subsequent page then loops through each 'checked' event, adding a record to the database for each event:</p> <pre><code>foreach ($_POST['registrations'] as $registration) { $query="SELECT exhibitions.exhib_id, DATE_FORMAT(exhibitions.exhib_date, %d/%m/%y'), venues.venue_name FROM exhibitions, venues WHERE exhibitions.venue_id='$registration' AND venues.venue_id='$registration' LIMIT 1"; $result=mysql_query($query); $vr=mysql_fetch_array($result, MYSQL_NUM); $exhib_id=$vr[0]; $exhib_date=$vr[1]; $exhib_venue=$vr[2]; // do database stuff here } </code></pre> <p>What I need to do is store each <code>$exhib_date</code> and <code>$exhib_venue</code> in a separate array, which I can reuse later (within a confirmation email, which will list all events the user has registered for).</p> <p>I thought this would be as simple as establishing a new array <b>outside</b> the foreach loop e.g. <code>$events_attending=array();</code> and adding elements to the array <b>within</b> the foreach loop e.g. <code>$events_attending['date'] = $exhib_date;</code> and <code>$events_attending['venue'] = $exhib_venue;</code>.</p> <p>I've tested this minus the foreach loop using <code>print_r()</code> and it works fine - so I'm guessing that's where my issue lies?</p> <p>Can anyone help at all? 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