creating functions using postgres database
So, i've been working with a website where an admin user (id of admin user
is 5) is the only one that can access the admin panel.
A small example is the admin panel button, this is a working code for that:
$rolesearch = pg_query($db, "SELECT * FROM myschema.peopletorole");
$rolematch = pg_fetch_row($rolesearch);
$person_id = $rolematch[0];
$role_id = $rolematch[1];
if (hasRole($person_id==$id && role_id==5)){
$admin = $p->header()->addButton('Admin Panel', 'adminpanel.php', 'a',
'gear', false, false, true);
$admin->rel('external');
}
But what i want to do now, is create a function that allows me to call the
function (say hasRole) and it grabs all the role_id's and person_id's from
the database. All i have to do is provide the hasRole() function with the
correct parameters. Here's what i've attempted, but it didn't work. Just
wondering what i did wrong. I'm fairly new to creating functions so bare
with me. Here's the code:
function hasRole ($person_id, $role_id){
$rolesearch = pg_query($db, "SELECT * FROM pbcschema.peopletorole");
$rolematch = pg_fetch_row($rolesearch);
$person_id = $rolematch[0];
$role_id = $rolematch[1];
return $person_id;
return $role_id;
}
No comments:
Post a Comment