Note that there are some explanatory texts on larger screens.

plurals
  1. POExtending PHP table function - behaviour for certain columns
    primarykey
    data
    text
    <pre><code>&lt;?php function f__table ($table,$cols,$order,$desc) { $comma=implode(",",$cols); $query = 'select '.$comma.' from '.$table.' order by '. $order.' '. $desc; $result = mysql_query($query); if (!$result) { $message = 'ERROR:' . mysql_error(); return $message; } else { $i = 0; echo '&lt;table class="tablesorter" width="960px;"&gt;&lt;thead&gt;&lt;tr&gt;'; while ($i &lt; mysql_num_fields($result)) { $meta = mysql_fetch_field($result, $i); //take table title and remove the F_prefix $title=$meta-&gt;name; $title=str_replace('F_','',$title); $title=str_replace('_',' ',$title); echo '&lt;th&gt;' . $title . ' &amp;nbsp;&amp;nbsp;&lt;/th&gt;'; $i = $i + 1; } echo '&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;'; $i = 0; while ($row = mysql_fetch_row($result)) { echo '&lt;tr&gt;'; $count = count($row); $y = 0; while ($y &lt; $count) { $c_row = current($row); echo '&lt;td&gt;' . $c_row . '&lt;/td&gt;'; next($row); $y = $y + 1; } echo '&lt;/tr&gt;'; $i = $i + 1; } echo '&lt;/tbody&gt;&lt;/table&gt;'; mysql_free_result($result); } // close connection mysql_close(); // close function } ?&gt; </code></pre> <p>I have this table function which is working well for my needs as a simple display if data from my mysql database to screen using some jQuery to add some functionality i.e. sorting columns, zebra row styling etc.</p> <p>However I now wish to explicitly extend my function to include a link in the html markup so for example in column 1 there might be values 1, 2, 3, 4 I wish to have a link to www.something.com/page/1 , /2 , /3 , /4 etc but in another example it might not be column 1 depending on my sql. I know in each case based on the fieldname which need to be links to other pages, a table might have 15 columns of which 6 of them may contain links in each td element of the table to a different page based on the value, </p> <p>I can specify this in an array perhaps, but how do I build this into a function so it is dynamic and extensible across my website? </p> <p>I have over 40 plus pages of data tables, charts and graphs on my website that I have coded by hand, I now wish to improve as my PHP skills have developed</p> <p>I believe I will need some if statements based on the array key (fieldname) as an indicator and if the array key exists in another array pull in the value from that array... if that makes sense.</p> <p>If anyone could provide an example of code or some logic and a pointer in the right direction that would be greatly appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload