[PHP] Dummy question about knowing marked checkboes

2005-05-29 Thread Mário Gamito
Hi,

First of all, my apologies to all list members for this dummy question.
I've made my home work before posting here, but the truth is that i
didn't found an answer for such a simple question.
Only examples of more sophisticated related things.

I have this piece of code that produces various checkboxes inside a form:
---
// select interesses names and values to build the chekboxes
$recordSet = $conn-Execute('SELECT interesses FROM interesses ORDER BY
interesses ASC');

// build the checkboxe's list
if (!$recordSet)
 print $conn-ErrorMsg();
else {
 while (!$recordSet-EOF) {
  print($recordSet-fields[0] . 'input name=\'interesses\'
type=\'checkbox\' id=\'interesses\' value=' . $recordSet-fields[0] .
'\'');
echobr /;
$recordSet-MoveNext();
}
$recordSet-Close();
$conn-Close();
}
-


Here's the correspondent HTML output:
-
Alojamentoinput name='interesses' type='checkbox' id='interesses'
value=Alojamento'br /
Artesanatoinput name='interesses' type='checkbox' id='interesses'
value=Artesanato'br /
Eventosinput name='interesses' type='checkbox' id='interesses'
value=Eventos'

(etc.)

-

My dummy question, for which i apologise once more is: after submitting
the form, how can i know which chekboxes were checked ?

Thanking you in advance.

Warm Regards,
Mário Gamito

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Dummy question about knowing marked checkboes

2005-05-29 Thread Tom Rogers
Hi,

Sunday, May 29, 2005, 5:50:13 PM, you wrote:
MG Hi,

MG First of all, my apologies to all list members for this dummy question.
MG I've made my home work before posting here, but the truth is that i
MG didn't found an answer for such a simple question.
MG Only examples of more sophisticated related things.

MG I have this piece of code that produces various checkboxes inside a form:
MG ---
MG // select interesses names and values to build the chekboxes
MG $recordSet = $conn-Execute('SELECT interesses FROM interesses ORDER BY
MG interesses ASC');

MG // build the checkboxe's list
MG if (!$recordSet)
MG  print $conn-ErrorMsg();
MG else {
MG  while (!$recordSet-EOF) {
MG   print($recordSet-fields[0] . 'input name=\'interesses\'
MG type=\'checkbox\' id=\'interesses\' value=' . $recordSet-fields[0] .
'\'');
MG echobr /;
$recordSet-MoveNext();
MG }
$recordSet-Close();
$conn-Close();
MG }
MG -


MG Here's the correspondent HTML output:
MG -
MG Alojamentoinput name='interesses' type='checkbox' id='interesses'
value=Alojamento'br /
MG Artesanatoinput name='interesses' type='checkbox' id='interesses'
value=Artesanato'br /
MG Eventosinput name='interesses' type='checkbox' id='interesses'
value=Eventos'

MG (etc.)

MG -

MG My dummy question, for which i apologise once more is: after submitting
MG the form, how can i know which chekboxes were checked ?

MG Thanking you in advance.

MG Warm Regards,
MG Mário Gamito

Make them an array by adding [] at the end of the name. Also you are
missing a quote at the start of the value=  (double quotes makes it
easier to print in my opinion)

It should be like this:

while (!$recordSet-EOF) {
  print($recordSet-fields[0] . 'input name=interesses[]
  type=checkbox id=interesses value=' . $recordSet-fields[0].''
);

Then any checkboxes checked  will be in an array called interesses

$interesses = (isset($_POST['interesses']))? $_POST['interesses'] :
array();
if(count($interesses)  0){
  //checkboxes have been ticked
}else{
  //none ticked
}

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php