Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By mdi45 on
I have a simple MYSQL table.
SELECT * FROM countries;
+----------------------------------------------------+
| id | country |
+----------------------------------------------------+
| 1| United Kingdom |
| 2| United States |
| 3| Afghanistan |
| 4| Albania |
+----------------------------------------------------+
I've searched hight & low.
What is the best way to query a MYSQL table (countries) and display the results in a Drupal page?
Comments
D8 API documentation ...
D8 API documentation ...
https://www.drupal.org/docs/8/api/database-api
https://www.drupal.org/docs/8/creating-custom-modules
spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...
custom query to fetch data from DB
$countryQuery = db_select('countries', 'cnt');
$countryData = $countryQuery
->fields('cnt', array('id','country'))
->orderBy('cnt.id', 'DESC')
->execute()->fetchAll();
Put it in your custom module and print $countryData, you can fetch all record from DB
I appreciate your help, but I
I appreciate your help, but I'm hoping that someone could write a very simple tutorial, similar to the list below:
1. Create the following mysql database, with the following contents:
name: hello_world_db
username: hello
password: world
SELECT * FROM hello_world_table;
+----------------------------------------------------+
| id | hello_text |
+----------------------------------------------------+
| 1| hello |
| 2| world |
+----------------------------------------------------+
2. Create files:
custom_module.module
custom_module.info
with contents
3. Install module
4. Create a Basic Article & show how to paste PHP code (if that is preferred way) or through hook & schema (if that is preferred way), so that you can view the hello_world_database contents.
I'm hoping that someone can write a very simplified tutorial similar to this. Thank you.
People here are not going to
People here are not going to write your code for you.
The free community help generously provided here will point you to tutorials about Drupal module building and so forth, but we are not going to build your module for you.
Read the Drupal 8 development docs at the links and watch some Drupal 8 module development tutorials on youtube.
spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...
Database queries in Drupal 8
Hello,
This is very good post for Database activities with Drupal 8 concern.http://www.eilyin.name/note/database-queries-drupal-8-7
And yes, we can only help. Writing full base code wont be possible here.
Thanks,
Sachin