Forum Moderators: coopster
$file_content = file('file.txt');
foreach($file_content as $data) {
$field = explode("¦" , $data);
$i++;
$class = ($i %2 == 0) ? 'right' : '';
echo "<li class=\"".$class."\" id=\"prod_".$field[0]."\"><p><a href=\"".$PHP_SELF."?prod=blinds&line=".$field[1]."\">".$field[2]."</a><br />\n";
echo "<a href=\"".$PHP_SELF."?prod=blinds&line=".$field[1]."\"><img src=\"images/".$field[3]."\" alt=\"".$field[2]."\" /></a></p></li>\n";
}
Can someone lend me a hand?
Thanks in advance :)
gen
Thanks anyway for trying, but I guess this subject just makes little sense to me. I guess I'll go with unordered output :)
Thanks for helping. I appreciate your time!
Cheers,
gen
function cmp($a, $b) {
$column_to_sort_on = 2;
if ($a[$column_to_sort_on] == $b[$column_to_sort_on]) return 0;
return ($a[$column_to_sort_on] < $b[$column_to_sort_on])? -1 : 1; } usort($file_content, "cmp");
foreach($file_content as $data) {
$field = explode("¦" , $data);
The above code will re-sort the output but definitely not alphabetically based on the column I've selected. For the life of me, I can't figure out why this is so difficult.
usort($file_content, "cmp");
id href text imgsrc
-- ---- ---- ---------
1 cats Cats /cats.jpg
2 dogs Dogs /dogs.jpg
3 bird Bird /bird.jpg
1¦cats¦Cats¦/cats.jpg
2¦dogs¦Dogs¦/dogs.jpg
3¦bird¦Bird¦/bird.jpg
$table = array();
foreach($file_content as $data) {
$table[] = explode('¦', $data);
}
usort($table, "cmp");