Javascript to PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rachel
    New Member
    • Nov 2011
    • 1

    Javascript to PHP

    I need to change this to PHP...the array must be in a text file that is read in and put into an array.




    Code:
    <?xml version="1.0"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Undergraduate Courses</title>
    <link rel="stylesheet" type="text/css" href="mystyles.css"/>
    <script type="text/javascript">
    
    
    
    var courseArray=new Array(); 
    courseArray[0]= new Array("ACC", "202", "Financial Accounting Information", "Fall08");
    courseArray[1]= new Array("CHEM", "126", "Chemistry and Society", "Fall08");
    courseArray[2]= new Array("GTW", "100", "Gateways I", "Fall08");
    courseArray[3]= new Array("ITM", "200", "Introduction to Computers-Lab", "Fall08");
    courseArray[4]= new Array("ITM", "200L", "Introduction to Computers-Lect", "Fall08");
    courseArray[5]= new Array("MAT", "260" ,"Calculus I" ,"Fall08");
    courseArray[6]= new Array("PSY", "200", "General Psychology", "Fall08");
    courseArray[7]= new Array("ENG", "101", "Composition and Rhetoric I (LC)", "Spring09");
    courseArray[8]= new Array("GIS", "101", "International Business", "Spring09");
    courseArray[9]= new Array("GTW", "102", "Gateways 2", "Spring09");
    courseArray[10]= new Array("ITM", "251", "Visual Basic", "Spring09");
    courseArray[11]= new Array("MAT", "261", "Calculus II", "Spring09");
    courseArray[12]= new Array("ENG", "102", "Composition and Rhetoric II", "Fall09");
    courseArray[13]= new Array("LAN", "110", "Basic American Sign Language I", "Fall09");
    courseArray[14]= new Array("MAT", "262", "Calculus III", "Fall09");
    courseArray[15]= new Array("MAT", "300", "Differential Equations", "Fall09");
    courseArray[16]=new Array("MUS", "110", "Piano Class I", "Fall09");
    courseArray[17]= new Array("LAN", "111", "Basic American Sign Language II", "Spring10");
    courseArray[18]=new Array("MAT", "299", "Intro to Higher Mathematics", "Spring10");
    courseArray[19]= new Array("MUS", "111", "Piano Class II", "Spring10");
    courseArray[20]= new Array("MUS", "191", "World Music", "Spring10");
    courseArray[21]= new Array("PHL", "202", "Ethics", "Spring10");
    courseArray[22]= new Array("BIO", "112", "Environmental Science", "Fall10");
    courseArray[23]= new Array("CRM", "101", "Introduction to Criminology", "Fall10");
    courseArray[24]= new Array("MAT", "301", "Discrete Mathematics", "Fall10");
    courseArray[25]= new Array("MAT", "410", "Complex Analysis", "Fall10");
    courseArray[26]= new Array("MUS", "192", "World Music Chorus/Drumming", "Fall10");
    courseArray[27]= new Array("ART", "101", "Form and Idea", "Spring11");
    courseArray[28]= new Array("MAT", "310", "Probability and Statistics", "Spring11");
    courseArray[29]= new Array("MAT", "499", "History of Mathematics", "Spring11");
    courseArray[30]= new Array("SOC", "100", "Intro to Sociology", "Spring11");
    courseArray[31]= new Array("DAN", "200", "Dance/World Cultures", "Fall11");
    courseArray[32]= new Array("DAN", "261", "Stretching and Relaxation", "Fall11");
    courseArray[33]= new Array("ITM", "360", "Advanced Application Development", "Fall11");
    courseArray[34]= new Array("JOU", "101", "Introduction to Journalism", "Fall11");
    courseArray[35]= new Array("MAT", "310", "Probability and Statistics", "Fall11");
    
    
    //displays the courses in a table format 
    function dosstable (array) 
    {
    document.writeln("<input type='button' value='back' onclick='window.location.reload()'>")
    document.writeln("<table border>");
    document.writeln( "<tr><th>Department</th><th>Number</th><th>Title</th><th>Semester</th></tr>");
    var row;
    for (row=0; row<array.length; ++row)
    {
    document.writeln("<tr>");
    var col;
    for (col = 0; col<array[row].length; ++col)
    {
    document.writeln("<td>" + array[row][col] + "</td>");
    }
    document.writeln("</tr>");
    }
    document.writeln("</table");
    return;
    
    }
    
    // gets the user's choice for semester (semester) and goes through courseArray to see if the semester in that course matches and then outputs the course(s) 
    function searchSemester(semester) 
    {
    var str = "<input type='button' value='back' onclick='window.location.reload()'>";
    str += "<table border><tr><th>Department</th><th>Number</th><th>Title</th><th>Semester</th></tr>";
    for(i=0; i<=courseArray.length-1;i++){
    if(document.getElementById('semester').value==courseArray[i][3]) //checks to see if semester is the same as the semester in that course 
    {
    str += "<tr>";
    for (var col = 0; col<courseArray[i].length; ++col)
    {
    str += "<td>" + courseArray[i][col] + "</td>";
    }
    str += "</tr>";
    }
      }
      document.writeln(str);
    }
    
    //gets the user's choice for department (department) and goes through courseArray to see if the department in that chouce matches and then outputs the course(s) 
    function searchDepartment(department){
    var str = "<input type='button' value='back' onclick='window.location.reload()'>";
    str +=  "<table border><tr><th>Department</th><th>Number</th><th>Title</th><th>Semester</th></tr>";
    for(i=0; i<=courseArray.length-1;i++){
    if(document.getElementById('department').value==courseArray[i][0]) //checks to see if semester is the same as the semester in that course 
    {
    str += "<tr>";
    for (var col = 0; col<courseArray[i].length; ++col)
    {
    str += "<td>" + courseArray[i][col] + "</td>";
    }
    str += "</tr>";
    }
      }
      document.writeln(str); 
    }
    
    </script>
    </head>
    <body>
        
    <p> <br/> <br/> </p>
    
    
    <label>Search by Semester:</label> 
    <select name="semester" id="semester">
    <option value="Default">Select a Semester</option>
    <option value="Fall08">Fall 08'</option>
    <option value="Spring09">Spring 09'</option>
    <option value="Fall09">Fall 09'</option>
    <option value="Spring10">Spring 10'</option>
    <option value="Fall10">Fall 10'</option>
    <option value="Spring11">Spring 11'</option>
    <option value="Fall11">Fall 11'</option>
    </select>
    <input type="button" value="Search" onclick="searchSemester('semester');" />
    <p> <br/> </p>
    
    
    
    
    <label>Search by Department:</label>
    <select id="department" name="department">
    <option value="Default">Select a Department</option>
    <option value="ACC">Accounting</option>
    <option value="ART">Art</option>
    <option value="BIO">Biology</option>
    <option value="CHEM">Chemistry</option>
    <option value="CRM">Criminology</option>
    <option value="DAN">Dance</option>
    <option value="ENG">English</option>
    <option value="GIS">Global Issues</option>
    <option value="GTW">Gateways</option>
    <option value="ITM">Information Technology</option>
    <option value="JOU">Journalism</option>
    <option value="LAN">Language</option>
    <option value="MAT">Mathematics</option>
    <option value="MUS">Music</option>
    <option value="PHL">Philosophy</option>
    <option value="PSY">Psychology</option>
    <option value="SOC">Sociology</option>
    <input type="button" value="Search" onclick="searchDepartment('department')"/>
    </select>
    </div>
    <p> <br/> </p>
    
    <input type="button" value="View All Courses" onclick= "dosstable(courseArray)"/> 
    
    </body>
    </html>
    Last edited by Dormilich; Nov 20 '11, 08:10 AM. Reason: please use [CODE] [/CODE] tags when posting code
  • pradeepkr13
    New Member
    • Aug 2010
    • 43

    #2
    Lot of manual work :)

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      yeah , go ahead do that, convert the whole of it, whos stopping :D
      regards,
      Omer Aslam

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        Simplest way to do that is open replace window in your editor

        select case sensitive
        Add new Array in search box
        add array in replace and press search next
        after finding next press replace button.

        it seems lot of work but simple technical way you can replace it :)

        Comment

        Working...