By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

PHP script for Arrays

P: 2
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
Feb 27 '07 #1
Share this Question
Share on Google+
3 Replies


The1corrupted
100+
P: 134
Instead of what you have, I suggest you use a str_replace(); tag so for example [PHP]
$freshman="Freshman";
if ($row[0][3]=="First Year") {
str_replace($row[0][3], $freshman, $container_string);
} elseif ($row[0][3]=="Second Year") { etc. etc. }
[/PHP]
And so on.
Feb 28 '07 #2

P: 2
Instead of what you have, I suggest you use a str_replace(); tag so for example [PHP]
$freshman="Freshman";
if ($row[0][3]=="First Year") {
str_replace($row[0][3], $freshman, $container_string);
} 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
Feb 28 '07 #3

The1corrupted
100+
P: 134
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?
Mar 1 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.