You are here: Re: array Issue - Correspoing checkbox and textfield values to behave « PHP Programming Language « IT news, forums, messages
Re: array Issue - Correspoing checkbox and textfield values to behave

Posted by Steve on 07/19/07 00:40

| <input type="checkbox" name="shows[]" value="Morning">Morning</
| option># of People<input type="text" name="people[]" value="" />
| <input type="checkbox" name="shows[]" value="Lunch">Lunch</option># of
| People<input type="text" name="people[]" value="" />
| <input type="checkbox" name="shows[]" value="Evening">Evening</
| option># of People<input type="text" name="people[]" value="" />
|
| ---------------------
| Current Problem
| ---------------------
| If I was to fill out the form and check off the "Evening" checkbox
| with 15 people in the textbox and looked at the arrays I would have
| the following:
|
| shows Array {
| [0] => Evening
| }
|
| people Array {
| [0] =>
| [1] =>
| [2] => 15
| }

seems about right. ALL 'text' type inputs will submit. only SELECTED
'checkbox'es submit. just change the html...

<input name='showTime[morning]' type='checkbox' value='morning'>
# of ppl <input name='people[morning]' type='text' value='0'>
<input name='showTime[lunch]' type='checkbox' value='lunch'>
# of ppl <input name='people[lunch]' type='text' value='0'>
<input name='showTime[evening]' type='checkbox' value='evening'>
# of ppl <input name='people[evening]' type='text' value='0'>

now try this:

foreach ($showTime as $timeOfDay => $value)
{
$attendees = $people[$timeOfDay]
if (!$attendees){ continue; }
echo '<pre>' .
($timeOfDay == 'lunch' ? 'At ' : 'In the ') .
$timeOfDay . ', there will be ' . $attendees .
' attendee' . ($attendees == 1 ? '' : 's') .
' coming to see the show.' .
'</pre>';
}

that's pretty straight-forward.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация