Hello,

I need to run a custom sql query and display it in a table what is the best way to do this?

Comments

Ok, haven't done this myself

Ok, haven't done this myself yet but maybe the VIEWS module allows this. Have a look at the module just in case.

*****************************
Drupal Projects Homepage (English): www.grandmacarmen.com
Drupal Video Tutorials (Spanish) : www.drupalcarmen.com

Nancy helped me :-)

There is a lady called Nancy ( She has made the drupal cookbook I think) she helped me like this.
Create a page and put this into it.

<?php
$sql
= 'SELECT sted, selskab, vej, username FROM {test}';
$header = array(
array(
'data' => 'sted', 'field' => 'sted'),
array(
'data' => 'selskab', 'field' => 'selskab'),
array(
'data' => 'vej', 'field' => 'vej'),
array(
'data' => 'username', 'field' => 'username'),
);

$sql .= tablesort_sql($header);

$result = pager_query($sql, 50);

while (
$data = db_fetch_object($result)) {
$rows[] = array($data->sted, $data->selskab, $data->vej, $data->username, str_repeat('--',$data->d).$data->title);
}

if (!
$rows) {
$rows[] = array(array('data' => t('Empty at the moment..'), 'colspan' => '4'));
}

echo
theme('table', $header, $rows);
echo
theme('pager', NULL, 50, 0);
?>

Is it something like this ?

Thanks!

Thanks stbdk, that was incredibly helpful. Finally helped me crack a problem I had been grappling with for days (how to build a View, or a View-like table, based on a custom query).

Regards: Colin

This helped me a lot as well,

This helped me a lot as well, thanks for sharing your idea.

Hi - I think I figured out at

Hi - I think I figured out at least part of what you're looking for, in the context of the views module in drupal6.10

http://drupal.org/node/409808