The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count by username
#1
Hello, I need some help pleasee, I wull like to count some tiket name by username login.

<pre>
Code:
$db = DB::getInstance();
$taskQ = $db->query("SELECT utilizator FROM task WHERE utilizator = $permOp->lname ",array($permOp->lname));
$task_count = $taskQ->count();
</pre>


will cont all my Id not my utilizator why ?
Can you help me ?
  Reply
#2
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.
  Reply
#3
OO, niceee here is the corect code:

<pre>
Code:
$taskQ = $db->query("SELECT utilizator FROM task WHERE utilizator = ? ",array($user->data()->lname));
$task_count = $taskQ->count();
</pre>


TYY for help
  Reply
#4
Now I need to select infomation base on login username like count total script:

<pre>
Code:
//Retrieve information for all users
function fetchAllTask() {
    $db = DB::getInstance();
    $query = $db->query("SELECT * FROM task WHERE utilizator = ? ",array($utilizator));
    $results = $query->results();
    return ($results);
}
</pre>

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>
  Reply
#5
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.
  Reply
#6
hoooooo, tyyy for help.

I fix the problem

<pre>
Code:
function fetchAllTask($utilizator) {
$db = DB::getInstance();
$query = $db->query("SELECT * FROM task WHERE utilizator = ? ",array($utilizator));
$results = $query->results();
return ($results); }
$TaskData = fetchAllTask($user->data()->lname); //Fetch information for all users
</pre>


tyy muadmin
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)