Click here to Skip to main content
15,845,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

i have a table components with n number of columns , but i need to display the columns in order or position passed as a parameters.

for example if i have 2 columns(Id,name) i need to pass a parameter 2 for id id to display it after the name so the result is (name,id)

anyone can help me please??!

1 solution

I assume you're putting the parameters into a server-side generated <table> element.

As you read each row of data from your query return, map it to an array element directly:
For example, if your have row element A, B, and C, and you wish to output them in the order B, C, A, then do the following:

if your sort order is in the array $order = (2,3,1);
$row = Get_The_Row_From_SQL_Return();

for($j=0; $j   $td[$order[$j]] = $row[j];

Now, use then array $td to create your table row:
 $rowText = '<table><tbody><tr>';

 foreach($td as $t)
   $rowText .= "<td>$t</td>";
 $rowText .= '';


You have now generated a table with data element position remapped.

Share this answer
MithalTirani 10-Jul-14 5:20am    
Sorry i'm using jasper table components to create a report

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900