1

I have a structure Student with one to many mapping and pushed values to it.Following is my code:

pragma solidity ^0.4.20;

 struct Student{

  uint id;
  string name;
  uint256 mark;

 }

 mapping(uint => Student[]) StudentDetails;

function addStudent(uint classid,uint id,string name,uint256 mark) public payable{

     StudentDetails[classid].push(Student(id,name,mark));
  }

Now I need to update mark field without updating id and name for each student. How it can be done? Help will be appreciated :)

  • By the least give us the prototype of the function that you need. – goodvibration Sep 25 '18 at 13:20
3

Refer the following function -

function updateStudent(uint classid,uint studentindex,uint id,uint256 mark) public payable{

     StudentDetails[classid][studentindex].mark = mark;
  }

Hope it helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.