Need help in writing a script

Hi,

I need help in the following things:

Below are the sample lines from my report. In this report I need to replace the “First year at school” , “Third year at school” with “Freshman” ,
" Junior " respectively. Simillarly, we will have second year, foruth year also to change to sophomore and senior respectively

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

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

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

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

I know that I need to traverse through each row then use conditions and replace the text but I am not sure how to do it.

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".

Please help me out.

Thanks in advance
Pragan

What you need to do is evaluate the current value of ‘class’ (assuming they’ll always be ‘First/Second/Third/Fourth year at school’):

[php]
for ($i = 0; $i < count($rows); $i++) { // Let’s loop through all the rows
if ($rows[$i][3]->val == “First year at school”) {
$rows[$i][3]->val = “Freshman”;
} elseif ($rows[$i][3]->val == “Second year at school”) {
$rows[$i][3]->val = “Sophmore”;
} elseif ($rows[$i][3]->val == “Third year at school”) {
$rows[$i][3]->val = “Junior”;
} elseif ($rows[$i][3]->val == “Fourth year at school”) {
$rows[$i][3]->val = “Senior”;
}
}
[/php]

This only works if $rows[][]->val works two-way ;)

Sponsor our Newsletter | Privacy Policy | Terms of Service