0

I did search for this but may be my search sucks. So posting it here..my code below

while( $row = mysqli_fetch_array($queryRecords) ) {
            $data['data'][] = array(
                        'student_name' => $row['name'],
                        'totalmark'    => $row['totalmark'],
                         $marksheet    =  calculatepercent(totalmark),
                         'resultdate'  => $row['resultdate'].$marksheet,
                         'ID'          => $row['ID']
                         );

Here I call function calculatepercent(totalmark) so that the function returns a value and store that in $marksheet. But my problem is this does not work i.e I cannot store the result of calculatepercent(totalmark) because I cannot access 'totalmark'

Forget performance for a minute but how do you make this work? (If you have tips for performance that's a bonus too! ) - Thanks Coders!

RR

3
  • 3
    You are missing a > in that array, also unless totalmark is a constant, you need to quote it. $marksheet => calculatepercent('totalmark'); Commented Jan 14, 2017 at 11:58
  • Is totalmark a constant? Commented Jan 14, 2017 at 11:58
  • I assume not, its more likely a switch case within the calculation script. One more note, you may have just missed it here, but check that there is a closing brace for the while loop. Commented Jan 14, 2017 at 12:00

2 Answers 2

1

Try like this.Send $row['totalmark'] to the calculatepercent() function.

while( $row = mysqli_fetch_array($queryRecords) ) {
            $data['data'][] = array(
                        'student_name' => $row['name'],
                        'totalmark'    => $row['totalmark'],
                         $marksheet    => calculatepercent($row['totalmark']),
                         'resultdate'  => $row['resultdate'].$marksheet,
                         'ID'          => $row['ID']
                         );
Sign up to request clarification or add additional context in comments.

1 Comment

That does not work sadly Hikmat. It does not just grab the data for i.e the line $marksheet => calculatepercent($row['totalmark']) Also I have all the closing braces. So that's not the issue. Only that line does not work as I can see other lines are working fine. Thanks!
0

I guess I was more desperate than any one else to get an answer! So after trying many things I got it working and sharing it here for any one else

while( $row = mysqli_fetch_array($queryRecords) ) {
   $marksheet = calculatepercent($row['totalmark'];


            $data['data'][] = array(
                        'student_name' => $row['name'],
                        'totalmark'    => $row['totalmark'],
          //move the fn 'calculatepercent' outside while loop  $marksheet  => //calculatepercent($row['totalmark']),
                         'resultdate'  => $row['resultdate'].$marksheet,
                         'ID'          => $row['ID']
                         );

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.