SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Array within Foreach
-
Oct 6, 2009, 09:00 #1
- Join Date
- Oct 2004
- Location
- uk
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Array within Foreach
Hi guys
I need to get the service[] array within the foreach.
I get this error
Warning: Invalid argument supplied for foreach() in timessetup.php on line 1043
How can I fix this
PHP Code:
foreach($_POST['date'] as $row=>$Act)
{
$starttimehour=mysql_real_escape_string($_POST['starttime1'][$row]);
$starttimeminute=mysql_real_escape_string($_POST['starttime2'][$row]);
$services=mysql_real_escape_string($_POST['service'][$row]);
echo"$services";
foreach($services as $s=>$Acts)
{
$sservices=mysql_real_escape_string($_POST['service'][$s]);
echo"$sservices";
}
Smarty page that sends the info
PHP Code:{foreach from=$times_array item=module key=key}
<tr>
<td>
{foreach from=$service_data item=servicesitem key=key}
<input type=checkbox name=service[] CHECKED value="{$servicesitem.Services_ID}"> <a href=editservice.php?id={$servicesitem.Services_ID} target=new>{$servicesitem.Name}</a><br />
{/foreach}
</td>
<td><input type=hidden name=date[] value="{$module|date_format:"%H:%M:%S"}"><input type=checkbox name=delete></td>
</tr>
{/foreach}
-
Oct 6, 2009, 11:46 #2
- Join Date
- Aug 2000
- Location
- Philadephia, PA
- Posts
- 20,578
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Since you haven't keyed these arrays at all in the form, you have no idea which set of service[] checkboxes go with which dates. You can't process that form unambiguously.
Right now your loop is just pulling the first dates, the first service checkbox. Then the second dates, the second service checkbox. The third dates, then the third service checkbox. It doesn't know if those checkboxes went with those dates, or if all 3 went with the first date, or what.Try Improvely, your online marketing dashboard.
→ Conversion tracking, click fraud detection, A/B testing and more
-
Oct 7, 2009, 10:14 #3
- Join Date
- Oct 2004
- Location
- uk
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thank you, could you show me a example of how i can match these up?
-
Oct 7, 2009, 10:38 #4
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:<input type="checkbox" name="data[1][service]"> <input type="text" name="data[1][date]"> <input type="checkbox" name="data[55][service]"> <input type="text" name="data[55][date]">
Then you get a nice structured array in php that you can loop over
PHP Code:print_r($_POST['data']);
Bookmarks