what is my problem is how about the data we apply as header not field name. any suggestion? tq
You could loop through your results set to reorder your data and create an array of data in your desired format. First task after returning the results of your select query would be to loop through rows and make an array of the first column to be used as headers and to index your values for the columns.
1. query data
2. create $colvals unique array of first column, use while loop
3. create a muli-dimensional array with num of cols and rows to hold data
4. loop through result rows and find index of col value in the $colvals array
this number will be uses as the col position of the values on each row to add the values in the new array
5. loop through rows and cols of the re-ordered data in the new array to print the results in an html table.
Heres the first part of getting the array of col1 values. If you get the rest of it or another solution post it.
// Performing SQL query
$query = 'SELECT * FROM vallist';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
It's hard to tell just by what you've told us about your table structure, but there is most likely an easier way to do this using SQL queries rather than creating and sorting arrays in php. If not maybe you should consider restructuring your tables. Could you post the table structures? And also, the SQL query you're using to gather your data.