PHP script for Arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • praganweb
    New Member
    • Feb 2007
    • 2

    PHP script for Arrays

    HI,

    I need help in the following things:

    We need to generate a report for the fields from the database. For example,

    StudentId Firstname Lastname Class
    101 abc def First year
    102 efg hjk Third year
    103 lmn rst First year

    I need to wrtie a script using php that will change the text under the heading as below

    StudentId Firstname Lastname Class
    101 abc def Freshman
    102 efg hjk Junior
    103 lmn rst Freshman


    This is how the output is needed.Replace each column with respective value.

    So basicallly I need to change "First Year" to "Freshman" , "Third year" to "Junior" and we will have second year, foruth year also to change to sophomore and senior respectively.

    I wrote this two lines to change the text with "Freshman" in all the places to just see how custom scripts works in the thrid party software.

    $class = "Freshman";
    $rows[0][3] ->val = $class; //this is the way I can call that column in this CRM software where I can define my scripts.

    StudentId Firstname Lastname Class
    101 abc def Freshman
    102 efg hjk Freshman
    103 lmn rst Freshman

    But I could not figure out the id for the each different value under the column "Class" or how to change each different value under the column "Class".

    It would be great if any one can help me in knowing the array structure in PHP..I can think of a way that I can write four if else conditions as I will have Four different values for the column " Class".

    For example :

    if ($rows[0][3] ->val = "First year"; //(I know I should call it through an id than calling it first year but I am not able represent it."
    {
    $rows[0][3] ->val = "Freshman"

    else
    {
    ....
    ....
    ....
    }
    }

    Please help me out.


    Thanks in advance
  • The1corrupted
    New Member
    • Feb 2007
    • 134

    #2
    Instead of what you have, I suggest you use a str_replace(); tag so for example [PHP]
    $freshman="Fres hman";
    if ($row[0][3]=="First Year") {
    str_replace($ro w[0][3], $freshman, $container_stri ng);
    } elseif ($row[0][3]=="Second Year") { etc. etc. }
    [/PHP]
    And so on.

    Comment

    • praganweb
      New Member
      • Feb 2007
      • 2

      #3
      Originally posted by The1corrupted
      Instead of what you have, I suggest you use a str_replace(); tag so for example [PHP]
      $freshman="Fres hman";
      if ($row[0][3]=="First Year") {
      str_replace($ro w[0][3], $freshman, $container_stri ng);
      } elseif ($row[0][3]=="Second Year") { etc. etc. }
      [/PHP]
      And so on.
      Hi,

      Thanks for the reply but it did not help me much as the records are from database so I tried connecting to the database and tried it but still no luck.Please let me know if you can help me further?
      I can explain you the problem again.

      Thanks

      Comment

      • The1corrupted
        New Member
        • Feb 2007
        • 134

        #4
        Originally posted by praganweb
        Hi,

        Thanks for the reply but it did not help me much as the records are from database so I tried connecting to the database and tried it but still no luck.Please let me know if you can help me further?
        I can explain you the problem again.

        Thanks
        I don't really understand why that wouldn't work, but perhaps I don't fully comprehend your issue. Each time a $row[0][3] would equal "First Year" it should replace the output with "Freshman", so did it help?

        Comment

        Working...