The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Count by username - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Documentation (https://userspice.com/forums/forumdisplay.php?fid=30) +--- Thread: Count by username (/showthread.php?tid=366) |
Count by username - picassoo - 11-26-2016 Hello, I need some help pleasee, I wull like to count some tiket name by username login. <pre> Code: $db = DB::getInstance(); will cont all my Id not my utilizator why ? Can you help me ? Count by username - mudmin - 11-26-2016 You were really close. Two things. 1. You usually don't need DB:getInstance because it is already called in the header for you and only needs to be called once. 2. When you are putting variables in queries, you put a ? where the variable would usually go. The reason for this is that it forces the query to ONLY look in that one particular table/column. It's a bit tricky, but it's called binding if you want to look it up. So, this should be what you need. Code: $taskQ = $db->query("SELECT utilizator FROM task WHERE utilizator = ?",array($permOp->lname)); Code: $task_count = $taskQ->count(); I hope that helps. Count by username - picassoo - 11-26-2016 OO, niceee here is the corect code: <pre> Code: $taskQ = $db->query("SELECT utilizator FROM task WHERE utilizator = ? ",array($user->data()->lname)); TYY for help Count by username - picassoo - 11-26-2016 Now I need to select infomation base on login username like count total script: <pre> Code: //Retrieve information for all users how can I do this in us_helpers.php ? Here is the form, where all info will go, <ul class="to_do"> <?php //Cycle through users foreach ($TaskData as $v1) { ?> <a>id?>"> <li class="list-group-item flat "> <input type="checkbox" class="list-group-item flat " name="update<?=$v1->id?>" value="<?=$v1->id?>" > <font color="<?=$v1->color?>"><i class="fa fa-circle"></i></font> <?=$v1->titlu?><span class="badge"><?=$v1->utilizator?> </span> </li> </a> <?php } ?> </ul> Count by username - mudmin - 11-26-2016 I can't tell exactly what you're trying to do, but it looks like you're missing one key part...how to get the utilizator into the function. So, I see three things... 1. You want to put your custom functions in usersc/includes/custom_functions.php . This way they will not get overwritten when we do updates. I do fix things and add functionality in both helpers.php and us_helpers.php and I wouldn't want you to miss those changes. 2. You need to pass the username into the function so you can do your query, so it should look like this... Code: function fetchAllTask($utilizator) { Then everything else looks good. Then when you run the function, you just do Code: fetchAllTask($user->data()->username); That should point you in the right direction. 3. I will say that it is probably better technique to base this on the user's id instead of their name. This will allow their data to remain intact if they change their username because the id will not change. Count by username - picassoo - 11-26-2016 hoooooo, tyyy for help. I fix the problem <pre> Code: function fetchAllTask($utilizator) { tyy muadmin |