I am making a website which displays table from a database. For every row of the table I want to provide a link(or button) which will be placed in the last column and will redirect to a page displaying records from another table associated with that row. Is there a way to create such link which would pass an argument (row id) to another page so it could display apropriate records? Thanks


You can use l() function, Like

Suppose You are showing some data in table format as you mention in your question and using some query you get some data from databse in $result variable,

$header = array(t('Approved By'), t('Role'), t('Points'), t('View More'));

foreach ($result as $row) {

    $rows[] = array($row['user_name'], $row['user_role'], $row['date'], l(t('View'), 'node/' . $row['row_id']));


return theme('table', array('header' => $header, 'rows' => $rows));

Now above code create a page showing table

Approved By    Role                    Points    View More
Eve            content writer          94        View    -> url: my-page/1

John           content manager         80        View    -> url: my-page/2

Adam           manager                 67        View    -> url: my-page/3
Jill           admin                   50        View    -> url: my-page/4

function my_module_menu() {
    $item['my-page/%'] = array(
        'title' => 'my page',
        'page_callback' => array()
        'page callback' => 'my_page_callback',
        'page arguments' => array(1),
        'access arguments' => array('access content overview')

return $item; }

function my_page_callback($row_id) {
    // Get some data from database using $row_id
    // show in table

  • That looks allright but my problem lies somewhere else. I need to pass the id of a row to a page function, which would fetch a set of rows from a database (not nodes) and display the table after clicking the link. I hope I made it clear this time.
    – Gregson
    Sep 3 '15 at 6:17
  • @Gregson: I have edited the answer, Hope this will solve your problem, let me know if you any issue.
    – Akash Jain
    Sep 3 '15 at 8:48
  • This works, thank you very much. Now it would be even better if I could do the same thing without displaying the data in the url address. If I won't find out how to do that, I will stick to this solution.
    – Gregson
    Sep 3 '15 at 10:52
  • It doesn't have to be based on url link, maybe I could use a set of form submit buttons, but I am not sure that it is possible in this situation or how to implement that kind of solution. Any ideas?
    – Gregson
    Sep 3 '15 at 11:18
  • Change url my-page/{row-id} to my-page and using javascript you can do that, on click just save row id in cookie, and then on page callback you will get value from cookie. But i am not recommend you to do in this way.
    – Akash Jain
    Sep 3 '15 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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