A
A
Alexey Usov2016-04-09 15:13:13
PHP
Alexey Usov, 2016-04-09 15:13:13

How to display the number of favorite tickets in ModX?

It is necessary to display the number of tickets that the user added to it (to favorites).
It does not work through pdoMenu, since tickets are not child elements, but the result of the snippet.
In the database, the picture is as follows:
54ab590317874abcbf236696cfbf7094.JPG
Here's how I first get only those ticket IDs whose id createdby is equal to the user id, and then count their number and output as a number?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Usov, 2016-04-28
@alekseenka

<?php
if (empty($user)) {
  $user = $modx->user->get('id');
}
if ($user == 0){
  return false;
}
$q = $modx->newQuery('TicketStar', array('class' => 'Ticket', 'createdby' => $user));
$q->select('id');
if ($q->prepare() && $q->stmt->execute()) {
  $count = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
}
echo count($count);

I
IceJOKER, 2016-04-09
@IceJOKER

SELECT COUNT(*) FROM modx_tickets_stars WHERE `createdby` = $user_id;

where $user_id = id of the current user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question