[RESOLVED] Switch Statement and Check boxes acting erratically?
Results 1 to 5 of 5

Thread: [RESOLVED] Switch Statement and Check boxes acting erratically?

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    32

    resolved [RESOLVED] Switch Statement and Check boxes acting erratically?

    Greetings, June 20th 2013

    I recently successfully achieved writing the values of 12 check boxes to file while using an array statement along with the check boxes arrayed. Now upon reading the values upon page load I used a switch statement to relate the file line to a variable that is echo'ed into the check boxes however the check boxes are erratically selected, checked. All of the numbers correspond and it should work the original file is correctly written and upon reloading the "echo" to the page as a test appears exactly as the file is written. Only when it enters the switch statement does thing appear to go awry and check boxes are erratically selected to represent no logical, detectable pattern?...any ideas?

    <?php if ($stat2=="1") { print 'checked="checked" '; } ?>

    Appreciatively,
    Ted

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Can you show us an example of the file's contents as well as the code you're using to read that file and output the appropriate HTML?

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    32
    The data from file is just basic as it was appended to file while each data field was written on it's own line. I have continually loaded the type file successfully. I was wondering if the increment wasn't incrementing appropriately? The below echo statement exactly portrays the file contents as it is written. something is lost at the switch or variable assignment unless I am mistaken...Any ideas? Appreciatively,

    if (file_exists($dfile)){
    $file1 = fopen($dfile, "r");
    while(!feof($file1))
    {
    $line = fgets($file1);
    echo "Line-".$numb." =====>".$line."\n";
    $numb++;
    if($numb>1){
    if (strlen($line)>5){
    switch ($numb)
    {
    case "2":
    $stat2="1";
    echo $stat2."\n";
    break;
    case "3":

  4. #4
    Un Re Member cretaceous's Avatar
    Join Date
    Sep 2004
    Location
    London UK
    Posts
    940
    try without the quotes on the case statements - $numb is an integer not a string
    case 2:
    $stat2="1"; // you can change this to $stat2=1 but that won't be the issue here
    echo $stat2."\n";
    break;
    case 3:

  5. #5
    Member
    Join Date
    Mar 2013
    Posts
    32
    Okay!...I was able to successfully and continually able to reload the 12 check box checks with the below. In the above the "Strlen" appears after the incrementing var if statement and after removing and revamping a bit all works great! below is the revision if anyone is interested..All of your help is greatly appreciated...

    if (file_exists($dfile)){
    $file1 = fopen($dfile, "r");
    //Output a line of the file until the end is reached
    while(!feof($file1))
    {
    $line = fgets($file1);
    if (strlen($line)>5){
    $dpos="1";
    //echo "Line-".$numb." =====>".$line."\n";
    }else{
    $dpos="0";
    }
    $numb++;
    if($numb>1){
    switch ($numb)
    {
    case 2:
    $stat2=$dpos;
    echo $stat2."\n";
    break;
    case 3:
    $stat3=$dpos;
    echo $stat3."\n";
    break;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •