I have a question about how to make this work...

Folks, I am trying to use php to read a flat file and display the output as an HTML table. So far I have been able to make the initial header row display and they are sortable but the data rows are just references to an array with no contents. Can anybody show me where I am going wrong?

<?php $sortby = $_SERVER['QUERY_STRING']; $set = ''; if ($sortby == '') { $header = 'Item Number'; $sortby = 'itemnumber'; $set = 'y'; } if ($sortby == 'Item Name') { $header = 'itemname'; $set = 'y'; } if ($sortby == 'Item Description') { $header = 'idescript'; $set = 'y'; } if ($sortby == 'Item Type') { $header = 'itemtype'; $set = 'y'; } if ($sortby == 'Item Color') { $header = 'itemcolor'; $set = 'y'; } if ($sortby == 'Item Size') { $header = 'itemsize'; $set = 'y'; } if ($sortby == 'Item Price') { $header = 'itemprice'; $set = 'y'; } if ($set == '') { echo 'The variable at the end of the web address did not match one required by the code. Please check the web address for errors.'; exit; } Bob's Database Read <?php echo

Bobs Database

To sort the columns click on the headers.

View the database
 

<?php $myFile = "C:\var\usr\bob1.csv"; $fp = fopen($myFile,'r'); if (!$fp) {echo 'ERROR: Unable to open file.
Item Number Item Name Item Description Item Type Item Color Item Size Item Price
'; exit;} <?php $row = 0; while (!feof($fp)) { $row++; $line = fgetscsv($fp,1024); //use 2048 if very long lines $field[$row] = explode('|', $line); if ($sortby == 'itemnumber') {$sortkey = strtolower($field[$row][0]);} //itemnumber if ($sortby == 'itemname') {$sortkey = strtolower($field[$row][1]);} //itemname if ($sortby == 'idescript') {$sortkey = strtolower($field[$row][2]);} //idescript if ($sortby == 'itemtype') {$sortkey = $field[$row][3];} //itemtype if ($sortby == 'itemcolor') {$sortkey = strtolower($field[$row][4]);} //itemcolor if ($sortby == 'itemsize') {$sortkey = strtolower($field[$row][5]);} //itemsize if ($sortby == 'itemprice') {$sortkey = $field[$row][6];} //itemprice array_unshift($field[$row], $sortkey); //add sortkey to start of array } fclose($fp); #sort($field); #reset($field); $arrays = count($field) - 1; $loop = -1; while ($loop < $arrays) { $loop++; '.$field[$loop][1].' '.$field[$loop][2].' '.$field[$loop][3].' '.$field[$loop][4].' '.$field[$loop][5].' '.$field[$loop][6].' '.$field[$loop][7].'
Sponsor our Newsletter | Privacy Policy | Terms of Service