I gang

Drupal API database call

I'm trying to improve a drupal database query that works and looks like:

$get_key = $this->connection->query("SELECT * FROM tablekeys WHERE id IN ( SELECT MAX(id) FROM tablekeys WHERE key = 'System' GROUP BY ip) ORDER BY id DESC");

The first SELECT gets all fields in table keys and ORDERS them by id DESC

The middle query in the same table get's the higher MAX id where field key = 'System' and GROUPS by ip

Also need to get a count of each grouped ip as count

The expected result is a list of grouped ip's that was ordered by max id and then ordered by id desc.

Example tablekeys

id, ip, key

1, [login to view URL], System

2, [login to view URL], System

3, [login to view URL], System

4, [login to view URL], System

5, [login to view URL], System

7, [login to view URL], Log

8, [login to view URL], Log

9, [login to view URL], System

10, [login to view URL], System

11, [login to view URL], System

This should return:

11, [login to view URL], System, Count 4

10, [login to view URL], System, Count 3

3, [login to view URL], System Count 1

Like I said the $get_key query does it except for the count.

But I need it done via latest drupal database API and to be inserted in a form that displays the table. So it need to be:

$get_key = $this->connection->select('tablekeys', 'u')

->fields('u', ['id', 'ip', 'key'])

->ETC.

and include:

->extend('Drupal\Core\Database\Query\TableSortExtender')->orderByHeader($header_key)

as the last order and limit for pagination

->extend('Drupal\Core\Database\Query\PagerSelectExtender')->limit(20)

and finish with:

->execute()->fetchAll();

Evner: Drupal, PHP, MySQL, Software Arkitektur

Se mere: drupal api, google maps api database integration, youtube api database, google maps api database, ebay api database, enom api database setup, drupal product database, drupal ajax database field, drupal league database, drupal mysql database, clamav api database version, drupal external database form, drupal localization database, google maps api database marker, google earth api database, google map api database open source, drupal search api database

Om arbejdsgiveren:
( 1 bedømmelse ) Reykjavik, Iceland

Projekt ID: #29066791

Tildelt til:

manuvelsubin

Hi, I hope you doing well. I have 8 year experience in Web Development using PHP, Sql. I saw the output you need. I can write it in a single query. Could we have a chat and move forward? Please give a chance to w Flere

$15 USD på 1 dag
(5 bedømmelser)
2.7

3 freelancere byder i gennemsnit $25 timen for dette job

anbarasakumar

Hi, you can use following statement to get count result too. ->addExpression('count(ip)', 'ip_node_count'); Thanks

$30 USD in 2 dage
(7 bedømmelser)
3.8
idvikster

Hello team, I'm ready to help you to improve a drupal database query. My team from InternetDevels - Drupal and WordPress development company did it a lot of times for 13 years of work: [login to view URL] Flere

$30 USD in 7 dage
(0 bedømmelser)
0.0