[SOLVED] Newbie Question about Do...While Loops
Posted: Tue Nov 25, 2003 4:23 pm
Overview of Problem
--------------------------
I have caught some information from a form with checkboxes and placed this into variables. The problem is that if the user doesnt click on a checkbox then the value passed will be nothing/null/zip/nadda, I want that value to be 'N' instead.
I have 30 of these checkboxes, I want all the variables that hold the information on these checkboxes to have a 'Y' or 'N'. The 'Y' is no problem as that value is passed when I access the $POST array. The 'N' value is what I am struggling with though.
I have come up with this code below to try and fix my problem. Instead of having 30 'If' statements I want to use a loop of some kind, but it's not working. I am a complete novice with PHP so i'm not sure if my logic is wrong or if it's something else.
I think the problem lies with ' if(!isset($atrib.$i)', basically what I am trying to do here is say if atrib1 is empty then put a 'N' in as the value for it. Of course each time the loop goes through 'i' will be incremented so the next time we get, if atrib2 is empty then put a 'N' in as the value for it.
Can anyone help me out here?
Thanks.
--------------------------
I have caught some information from a form with checkboxes and placed this into variables. The problem is that if the user doesnt click on a checkbox then the value passed will be nothing/null/zip/nadda, I want that value to be 'N' instead.
I have 30 of these checkboxes, I want all the variables that hold the information on these checkboxes to have a 'Y' or 'N'. The 'Y' is no problem as that value is passed when I access the $POST array. The 'N' value is what I am struggling with though.
I have come up with this code below to try and fix my problem. Instead of having 30 'If' statements I want to use a loop of some kind, but it's not working. I am a complete novice with PHP so i'm not sure if my logic is wrong or if it's something else.
Code: Select all
<?php
$atrib1=Y;
$atrib2=Y;
$atrib3=Y;
$atrib4=Y;
$atrib5=Y;
$atrib6=NULL;
$atrib7=NULL;
$atrib8=NULL;
$atrib9=NULL;
$atrib10=NULL;
$atrib11=NULL;
$i=1; //sets up a counter for the loop
do {
if(!isset($atrib.$i)
$atrib.$i = "N";
$i++;
else {
$i++;
}
while ($i<12);
echo $atrib1;
echo $atrib2;
echo $atrib3;
echo $atrib4;
echo $atrib5;
echo $atrib6;
echo $atrib7;
echo $atrib8;
echo $atrib9;
echo $atrib10;
echo $atrib11;
?>I think the problem lies with ' if(!isset($atrib.$i)', basically what I am trying to do here is say if atrib1 is empty then put a 'N' in as the value for it. Of course each time the loop goes through 'i' will be incremented so the next time we get, if atrib2 is empty then put a 'N' in as the value for it.
Can anyone help me out here?
Thanks.