Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:44:26+00:00 2026-05-25T01:44:26+00:00

<?php function f__table ($table,$cols,$order,$desc) { $comma=implode(,,$cols); $query = ‘select ‘.$comma.’ from ‘.$table.’ order by

  • 0
<?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 '<table class="tablesorter" width="960px;"><thead><tr>'; 
    while ($i < mysql_num_fields($result))  { 
    $meta = mysql_fetch_field($result, $i);
    //take table title and remove the F_prefix
    $title=$meta->name;
    $title=str_replace('F_','',$title); 
$title=str_replace('_',' ',$title); 
    echo '<th>' . $title . '  &nbsp;&nbsp;</th>'; 
    $i = $i + 1; 
    } 

    echo '</tr></thead><tbody>'; 
    $i = 0; 
    while ($row = mysql_fetch_row($result)) 

    { 
    echo '<tr>'; 
    $count = count($row); 
    $y = 0; 
    while ($y < $count) 
            { 
            $c_row = current($row); 
            echo '<td>' . $c_row . '</td>'; 
            next($row); $y = $y + 1; 
            } 
echo '</tr>'; 
$i = $i + 1; 
} 

echo '</tbody></table>';
mysql_free_result($result); 
} 
// close connection
mysql_close();
// close function
}
?>

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.

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 http://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,

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?

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

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.

If anyone could provide an example of code or some logic and a pointer in the right direction that would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:44:27+00:00Added an answer on May 25, 2026 at 1:44 am

    create a function for each part of the table creation, header and display, with functions for different display properties e.g a link or image.

    create an array for fieldnames akin to:
    (name, width, alignment, behaviour).

    'F_DESCRIPTION' => array( 'Description', 210, 'left', '_function_display' ),
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This example is from php.net: <?php function Test() { static $a = 0; echo
I have the following in php: public function myfunction($v){ //ini_set(memory_limit,32M); $v=mysqli_real_escape_string($this->connection,$v); $stmt=mysqli_prepare($this->connection,SELECT * from
PHP functions such as 'array_map' take a callback, which can be a simple function
in function need key to encrypt string without mcrypt libraly in php function encrypt($str,
Is there a Php function to determine if a string consist of only ASCII
I have a php function I wrote that will take a text file and
Is there a php function that someone can use to automatically detect if an
I'm using the PHP function imagettftext() to convert text into a GIF image. The
How can I get a PHP function go to a specific website when it
is there an alternative for mysql_insert_id() php function for PostgreSQL? Most of the frameworks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.