tags:

views:

31

answers:

2

I am using following class to show a grid like appearance with pagination on my home page. The class is very good and is working fine.

When the grid shows records, I just want to make the second column values as a hyperlink. I tried adding a href ... in the class where $c is updating, but it is not working. Can anyone help me out.

This class also uses "style.css" file that is also available from the link below. Are any changes needed there?

http://www.webmastergate.com/php/paginate-query-results.html

+1  A: 

In the function getRows(), near the very last lines of the function where the $c variable is set. You have to somehow test whether this is the column you want to add the link. Suggest that you set up another associative array which store a key and a callback function

   $r = '';
 while ($row = mysql_fetch_assoc($result)) {
  $c = '';

  foreach($row as $key=>$field) {
                //manipulate data here
   $c .= $this->fmtField($key, $field);
  }
  $r .= sprintf($this->rowfmt, $cr ? $classodd : $classeven, $c);
  $cr = 1 - $cr;
 }

Another datagrid I will recommend is http://www.eyesis.ca/projects/datagrid.html - it partly removes the need to add in link as you can add custom actions to each row.

Extrakun
Thanks for that alternative solution.
RPK
+1  A: 

You can't. You can delegate the responsibility to the formatting to the mysql query for a possible workaround.

for example you can format the query like this one:

SELECT firstField, 
    concat ('<a href="', secondField, '">', thirdField,'</a>') as link_column, 
    ....

assuming that in the second field you have the URL and in the third one you saved the text of the link.

Another solution (no text) can be

SELECT firstField, 
    concat ('<a href="', secondField, '">', secondField,'</a>') as link_column,
    ....

If you need to show the URL other than make the link.

I've perused the class and think there aren't other solution without modifying it because you can't address a single column in a row.

Eineki