În desfăşurare

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'])


and include:


as the last order and limit for pagination


and finish with:


Aptitudini: Drupal, PHP, MySQL, Arhitectură software

Vezi mai multe: 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

Despre angajator:
( 1 părere ) Reykjavik, Iceland

ID Proiect: #29066791

Acordat lui:


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 Mai multe

%selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% USD în 1 zi
(5 Recenzii)

3 freelanceri licitează în medie 25$ pentru acest proiect


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

%bids___i_sum_sub_35%%project_currencyDetails_sign_sub_36% USD în 2 zile
(7 recenzii)

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] Mai multe

%bids___i_sum_sub_35%%project_currencyDetails_sign_sub_36% USD în 7 zile
(0 recenzii)