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

madmatt

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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.
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
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

Awesome is as awesome does.
Political Access
Joined
5 Apr 2002
Messages
13,314
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:

falconguard

Carbon based lifeform
Political Access
Joined
11 Feb 2004
Messages
3,406
Just a question, but if you are using a three tiered array shouldn't your set be 0,1,2?
 

Geffy

OSNN Veteran Addict
Joined
18 Mar 2002
Messages
7,805
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
 

Members online

No members online now.

Latest profile posts

Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.
Terrahertz wrote on Electronic Punk's profile.
Yo fellas!
Electronic Punk wrote on Sazar's profile.
Where are you buddy?
Perris Calderon wrote on Electronic Punk's profile.
Hey EP! All good with me, applying for Microsoft MVP right now, should have done this a while ago.

Notifications don't work, I only found your response by coming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier!
Perris Calderon wrote on Electronic Punk's profile.
EP, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there!

Forum statistics

Threads
61,997
Messages
673,411
Members
5,590
Latest member
AntonioPR