How to convert (this code) from ASP to PHP?

Discussion in 'Web Design & Coding' started by madmatt, Feb 26, 2007.

  1. madmatt

    madmatt Bow Down to the King Political User

    Messages:
    13,312
    Location:
    New York
    I am a pretty good ASP coder (maybe you'll think otherwise after seeing my code) and I am still learning PHP. I need to convert the following code from ASP to PHP. First one to help gets cookies!

    Code:
      ' Start of workType Counter
    
      msgBody = msgBody & "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>"
    
      workTypeCount = 1
      workTypeCounter = Request.Form("workType").Count
    
      If workTypeCount <= workTypeCounter Then
        msgBody = msgBody & "<b>" & Request.Form("workType")(1) & " (" & Request.Form("fullTimeShift") & " Shift)</b><br>"
        workTypeCount = workTypeCount + 1
      End If
      If workTypeCount <= workTypeCounter Then
        msgBody = msgBody & "<b>" & Request.Form("workType")(2) & " (" & Request.Form("partTimeShift") & ")</b><br>"
        workTypeCount = workTypeCount + 1
      End If
      If workTypeCount <= workTypeCounter Then
        msgBody = msgBody & "<b>" & Request.Form("workType")(3) & " (" & Request.Form("tempDate1") & "-" & Request.Form("tempDate2") & ")</b>"
        workTypeCount = workTypeCount + 1
      End If
    
      msgBody = msgBody & "</td></tr>"
    
      ' End of workType Counter
    
    Thank you.
     
  2. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    Maybe this

    PHP:
    <?php
    // ' Start of workType Counter
    // 
    //   msgBody = msgBody & "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>"
    // 
    //   workTypeCount = 1
    //   workTypeCounter = Request.Form("workType").Count
    // 
    //   If workTypeCount <= workTypeCounter Then
    //     msgBody = msgBody & "<b>" & Request.Form("workType")(1) & " (" & Request.Form("fullTimeShift") & " Shift)</b><br>"
    //     workTypeCount = workTypeCount + 1
    //   End If
    //   If workTypeCount <= workTypeCounter Then
    //     msgBody = msgBody & "<b>" & Request.Form("workType")(2) & " (" & Request.Form("partTimeShift") & ")</b><br>"
    //     workTypeCount = workTypeCount + 1
    //   End If
    //   If workTypeCount <= workTypeCounter Then
    //     msgBody = msgBody & "<b>" & Request.Form("workType")(3) & " (" & Request.Form("tempDate1") & "-" & Request.Form("tempDate2") & ")</b>"
    //     workTypeCount = workTypeCount + 1
    //   End If
    // 
    //   msgBody = msgBody & "</td></tr>"
    // 
    //   ' End of workType Counter

    $msgBody "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>";

    $workTypeCount 1;
    $workTypecounter count($_POST['workType']);

    if (
    $workTypeCount <= $workTypeCounter) {
        
    $msgBody .= "<b>" $_POST['workType'][1] . " (" $_POST['fullTimeShift'] . " Shift)</b><br>";
        
    $workTypeCount += 1;
    }

    if (
    $workTypeCount <= $workTypeCounter) {
        
    $msgBody .= "<b>" $_POST['workType'][2] . " (" $_POST['partTimeShift'] . ")</b><br>";
        
    $workTypeCount += 1;
    }

    if (
    $workTypeCount <= $workTypeCounter) {
        
    $msgBody .= "<b>" $_POST['workType'][3] . " (" $_POST['tempDate1']  . "-" $_POST['tempDate2'] . ")</b><br>";
        
    $workTypeCount += 1;
    }

    $msgBody .= "</td></tr>";
    ?>
     
    madmatt likes this.
  3. madmatt

    madmatt Bow Down to the King Political User

    Messages:
    13,312
    Location:
    New York
    I'll give that a go. Thank you.

    EDIT: No go. $workTypeCounter isn't being set so it doesn't go through the rest of the script.

    EDIT #2: $workTypeCounter isn't being set correctly.

    EDIT #3: Making progress. I found out that I needed to modify the name of my check boxes. I added a "[]" to the end and I am getting some where.
    EDIT #4: Got it. Changing the array to 0 through 3 made it work perfectly. Thanks again Geffy.

    PHP:
    <?php

      $msgBody 
    "<tr><td width=62% class=E1>When are you available to work?</td><td width=38% class=E1>\n";

      
    $workTypeCount 1;
      
    $workTypeCounter count($_POST['workType']);

      if (
    $workTypeCount <= $workTypeCounter) {
        
    $msgBody .= "<b>" .$_POST['workType'][0] ." (" .$_POST['fullTimeShift'] ." Shift)</b><br>\n";
        
    $workTypeCount += 1;
      }
      if (
    $workTypeCount <= $workTypeCounter) {
        
    $msgBody .= "<b>" .$_POST['workType'][1] ." (" .$_POST['partTimeShift'] ." Time)</b><br>\n";
        
    $workTypeCount += 1;
      }
      if (
    $workTypeCount <= $workTypeCounter) {
        
    $msgBody .= "<b>" .$_POST['workType'][2] ." (" .$_POST['tempDate1']  ."-" .$_POST['tempDate2'] .")</b><br>\n";
        
    $workTypeCount += 1;
      }

      
    $msgBody .= "</td></tr>\n";

    ?>
    EDIT #5: Of course this method breaks my error checking.

    Code:
      var multiCheckbox = false;
      for (i = 0; i < document.app.workType.length; i++) {
        if (document.app.workType[i].checked)
        multiCheckbox = true;
      }
      if (!multiCheckbox) {
        errorMsg += "\nWork Availability\nPlease select full-time, part-time, and/or temporary.\n";
      }
    
     
    Last edited: Feb 26, 2007
  4. falconguard

    falconguard Carbon based lifeform Political User Folding Team

    Messages:
    3,406
    Location:
    SoCal
    Just a question, but if you are using a three tiered array shouldn't your set be 0,1,2?
     
  5. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    He's caught that. Sorry I'd just done a pretty much line by line port of the ASP without checking things like indexes :p

    my bad