hello!
I've an external database width a table named "testable".
My table is like this :

http://hpics.li/2d51ae7

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

Jaypan’s picture

$result = db_query('SELECT titre FROM {testable}');
foreach($result as $record)
{
  $record = $result->fetchField();
  print $record;
}
nico38’s picture

Thanks!
I've written the code :

db_set_active('my_other_db');
	$result = db_query('SELECT titre FROM {testable}');
	foreach($result as $record)
	{
	  $record = $result->fetchField();
	  print $record;
	}
//fin
db_set_active();

But there is no loop. Only the last value is displaying (not all the values in the field "titre")

id titre desc
1 titre1 NO DISPLAY desc1
2 titre2 DISPLAY desc2
Jaypan’s picture

The code you've shown will loop. So your problem is somewhere else.

nico38’s picture

You are right.
In fact, 1 in 2 lines of database are skipped

id titre desc
1 titre1 NO DISPLAY desc1
2 titre2 DISPLAY desc2
2 titre3 No DISPLAY desc2
2 titre4 DISPLAY desc2
2 titre5 No DISPLAY desc2
2 titre6 DISPLAY desc2