Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By nico38 on
hello!
I've an external database width a table named "testable".
My table is like this :
id | titre | desc |
---|---|---|
1 | titre1 | desc1 |
2 | titre2 | desc2 |
I want to display the content of fields.
To display one field I write :
<?php
db_set_active('my_other_db');
$result = db_query("SELECT titre FROM testable WHERE titre='titre 1'");
$record = $result->fetchField();
print $record;
db_set_active();
?>
But how display all content of field "titre" ?
I tried using fetchAll but no success...
$result = db_query("SELECT titre FROM testable");
$record = $result->fetchAll();
print $record;
Comments
$result = db_query("SELECT
loop
Thanks!
I've written the code :
But there is no loop. Only the last value is displaying (not all the values in the field "titre")
The code you've shown will
The code you've shown will loop. So your problem is somewhere else.
You are right.
You are right.
In fact, 1 in 2 lines of database are skipped