0

I am currently displaying a list of MySQL database table names, such as table1, table2, table3.

Each table name will be a link; if users click on it, it will display them the data contained in that table.

One way I know I can do this is to create a Drupal page that contains the content of "table1", so that when a user clicks on "table1", they are taken to this page and can see the data of "table1".

However, this soon becomes un-manageable if I have a large databases with many tables.

I'm not quite sure if Drupal can work in this way, but I would like it so that when a user clicks on a table link (either table1 or table2 and so on), the current or a generic page will then be updated with the content of the table chosen and be updated with its content.

2
  • Are you doing this in Code (e.g. a module) or by hand?
    – Berdir
    Commented Mar 13, 2012 at 20:40
  • Berdir, I am doing this through PHP code in a Drupal content. However, if there is an easier way, please let me know.
    – chlong
    Commented Mar 13, 2012 at 20:55

2 Answers 2

1

I am not sure what functionality you are trying to build and if adding PHP code inside a Drupal node is the right way to do it. But assuming that is what you would like to do, here are the steps to achieve what you want:

  1. Create a Drupal node (say the nid of it is NID) and add the following PHP code inside it

    $table_name = arg(2); // This grabs the 3rd argument of the page menu path (note: the 1st argument is indexed 0)
    print $table_name; // Replace this with PHP code to fetch and print data in the table represented by $table_name
    
  2. When you are making table1, table2 etc links make sure the URL that they point to is node/NID/<table_name> where <table_name> is table1, table2 respectively.

3
  • 1
    Using PHP code inside a node is generally not a good idea.
    – apaderno
    Commented Mar 14, 2012 at 9:04
  • @Sumeet, thank you for the response, I believe you have understood me correctly. Could you please tell me how I can find the node ID of the current node or any node? Thanks.
    – chlong
    Commented Mar 14, 2012 at 17:27
  • @Sumeet, I have found out how to find the node ID. Thanks. I will try and let you know. What if I have enabled clean URLs and have created a URL for this node? How should I reference the node then?
    – chlong
    Commented Mar 14, 2012 at 17:33
0

If you have a dynamic list of tables/columns, then you can build this using PHP, you just need a dynamic menu entry that accepts the table name as an argument and then you can re-act to that in PHP. There are many books and online documentation available about how to create modules, try here for example: http://drupal.org/node/361112

If you have a fixed list of tables, you could build this using Views. If these are custom tables, you first will integrate them with Views, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.