jason246day
Programmer
I have a file full of data entries that are displayed on a page, file is reversed before displaying so the last element will display first. I am trying to create a feature that will allow a user to ascend and descend an element in the list. Basically it will flip flop two sequential lines in a file. I think my logic is right, but for some reason it won't replace the values. Anyone have any ideas on this???
Code:
$old_stock=file("db/stock_shop.txt");
$stock_count = count($old_stock);
foreach($old_stock as $old_stock_line) {
echo "$old_stock_line<br>";
}
for($z=1; $z < $stock_count-1; $z++){
$first_entry=$old_stock[$z];
$second_entry=$old_stock[$z+1];
$exploded=explode("|", $first_entry);
if($exploded[0]==$id){
$old_stock[$z]=$second_entry;
$old_stock[$z+1]=$first_entry;
}
}
echo "<br><br>";
foreach($old_stock as $old_stock_line) {
echo "$old_stock_line<br>";
}