The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Fetch data from DB - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: Fetch data from DB (/showthread.php?tid=100) |
Fetch data from DB - jjmmrg - 03-13-2016 Dear UserSpice Team , I am a newbie to user spice and just started working on PhP MYSQL . of course i love to work in this for the reason it gives me flexibility to make changes on the top of your framework without any restriction . My query is i need to display the role of the user logged in . Like if he is Administrator then echo as Administrator I am taking Permission id of the logged in user from users table and comparing it with the id in Permission table and trying to fetch the name of the role from the permission table . But it displays the following error . <pre> Code: Notice: Array to string conversion in C:\xampp\htdocs\***\account.php on line 477 My code is as follows <pre> Code: <?php Fetch data from DB - jjmmrg - 03-14-2016 Since results is obviously an array i just noticed and used print_r($results); in replace of echo . still i am getting only as follows Code: Array ( [0] => stdClass Object ( [id] => 100 ) ) Fetch data from DB - jjmmrg - 03-14-2016 Then i tried to access that using Code: $results[0]->id; but actually it outputs as Code: 100 Code: name Code: Permission table Code: "Administrator" Code: 100 Fetch data from DB - jjmmrg - 03-14-2016 No i tried the following <pre> Code: <?php It results nothing . Just blank . I am really really worried without knowing where i am doing mistake Fetch data from DB - brian - 03-14-2016 This code will dump out the names of the groups the logged in user belongs to. Give it a try and come back with any questions. <pre> Code: $db = DB::getInstance(); Fetch data from DB - mudmin - 03-14-2016 Yeah. Off the top of my head, that looks right. Great answer. If that doesn't work, let me know. I can also make a little function to make that easier in the future. Fetch data from DB - brian - 03-14-2016 The trick here is that the user still needs to "assign meaning" to the different levels. In my case, I run a query to see if they have permission level 2 or 3 (Admin and Moderator) while level 3 is only Moderator (no admin) and that allows or generates pages based on the level. The more we know about what you need to do , the better we can tailor a response. Fetch data from DB - jjmmrg - 03-15-2016 @brian , That worked perfectly . Thanks a ton . @brian and @mudmin One more query . Why come there are two ids in user_permission_matches table with same user_id . for ref check the demo db table after installing userspice 4.0 mate . User with 101 also has user_id 1 and Administrator with id 100 also has user_id 1 Fetch data from DB - jjmmrg - 03-15-2016 @brain and @mudmin in addition to the previous reply i also have one more query if i output Code: <?php echo $user->data()->join_date; ?> Code: 2016-01-01 00:00:00 Code: January 2016 Fetch data from DB - jjmmrg - 03-15-2016 I solved the above with the following query mate <pre> Code: <?php However kindly answer for my other question before to that . |