String replace

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 8
Joined: Wed May 08, 2013 9:18 am

Sun May 12, 2013 9:06 am

Hi everyone!
I am stuck and I need some fixing. I am creating a certificate generating system. the certicate contains subjects which should be replaced with grades per each student stored in mysql table. The student details, subject and the grade per each subject is stored in table results. I have writen the following code:
$query_getResults="select grade from results where studentnumber='$studentnumber'";

I want to replace subject1 with corresponding subject name from th database , then subject2 and so forth. I also want once the <<subject>> place holder is replaced, should be assigned the relevant grade from the database.

I want the string above to look like the one below after replacement with database values:
Maths A
English B
Computer studies B+
I wrote the code below but cannot not work, can only replace with a single value. The array seem not to work for me.
@header("content-Disposition:inline, filename=cert.rtf");

//open template file
//read the template into a varriable
//replace the place holders in the template with new data


//generate output
echo $output;

Any assistance please?

New php-forum User
New php-forum User
Posts: 20
Joined: Tue Mar 06, 2012 11:05 pm

Sun May 12, 2013 10:15 pm


I guess, a student will have more than one subject and grade as well. But here in your code while retrieving the data from the database, you are storing the data to a variable. So in each loop the variables gets updated. In this way it will have the value of last subject and grade.

So here you need to store the data(subjects and grades) in an array. Then in cert file just loop thru the array and write the subject and respective grade.

I guess this will help you.

Swarup Sahu

Post Reply