Welcome Guest, Not a member yet? Register   Sign In
user control - Can this be done easy


I'm creating a website, using sessions to tell wich type of users i have

Its three levels: guest, user and admin

if guest, noe session is set, if user og adminĀ  session()->get('role') contains 'user'or 'admin'

And i need to get som different queries done depending on role.

Today i do it like this

PHP Code:
if (!session()->get('role') == "user" || !session()->get('role') == "admin") {

//query for guests
$query $db->query("SELECT recipes.*, kategori.kategori FROM recipes JOIN kategori ON recipes.category_id=kategori.kategori_id WHERE recipes.category_id = " $id " AND recipes.approved = 'yes';");

} elseif (
session()->get('role') == "user") {

//query for users
$query $db->query('SELECT recipes.*, kategori.kategori FROM recipes JOIN kategori ON recipes.category_id=kategori.kategori_id WHERE recipes.category_id = "' $id '" AND (recipes.created_by = "'session()->get('id').'" OR recipes.approved = "yes");');

} elseif (
session()->get('role') == "admin") {

//query for admin
$query $db->query("SELECT recipes.*, kategori.kategori FROM recipes JOIN kategori ON recipes.category_id=kategori.kategori_id WHERE recipes.category_id = " $id ";");
} else {
<p>An error occured.</p>

This works, but was just wondering if there was any simpler way to achieve this. Because i have to use this on multiple controls/views

Messages In This Thread
user control - Can this be done easy - by bengtdg - 06-02-2021, 02:51 AM

Theme © iAndrew 2016 - Forum software by © MyBB