this code require two input(_Id,_name) to get age i need to get name and age from input id only
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract nestmap
{
mapping(uint256=>mapping(string=>uint256)) public User;
function adduser(uint256 _Id,string memory _name, uint256 _age)public {
User[_Id][_name]=_age;
}
}
function user(uint256 _Id,string memory _name)public view returns(uint256)
{
return User[_Id][_name];
}
mapping
describes a data structure where eachid
has a large number ofstring
keys, and each of those maps to auint256
, so probably not what you want. It's roughtlykey1 => key2 => value
, hence two keys are requested. I voted for Yongjian's answer. That's probably what you want.