a table with the correct info, the last cell cotains the key in the array, witch is correct
Code: Select all
<?php // <<added to easy read on forum...
if($showmodels) {
if($_POST['manufacturerselect']) {
$man_name = $_POST['manufacturerselect']; //set var to selected manufacturer
} elseif ($_POST['selman']) {
$man_name = $_POST['selman']; //set var to manufacturer that was previsoly stored
}
$sql = "SELECT * FROM bytin_manufacturer WHERE manufacturer_name='$man_name'";
$query = mysql_query($sql);
$rows = mysql_fetch_array($query);
$models = $rows['manufacturer_models'];
$file = fopen($modelfile,'w');
fwrite($file,$models);
fclose($file);
$array = unserialize($models);
?>
<form name="models" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<input type="hidden" name="selman" value="<?php echo($man_name) ?>"/> <!-- Store our manufacturer -->
<table border="1">
<tr>
<td width="100px;">Modell</td>
<td width="100px;">Pris</td>
<td width="150px;">Avdrag utan kartong</td>
<td width="50px;">Edit</td>
<td width="50px">Delete</td>
</tr>
<?php
$c = count($array);
for($i = 0;$i < $c;$i++) { // Create table with model info
?>
<tr>
<td width="100px;"><?php echo($array[$i][0]); ?></td>
<td width="100px;"><?php echo($array[$i][1]); ?></td>
<td width="150px;"><?php echo($array[$i][2]); ?></td>
<td width="50px;">
<input type="hidden" name="editindex" value="<?php echo($i); ?>">
<input type="submit" name="modelindexedit" value="Edit"/>
</td>
<td width="50px">
<input type="hidden" name="delindex" value="<?php echo($i); ?>">
<input type="submit" name="modelindexdel" value="Delete"/>
</td>
<td>
<?php echo($i); ?>
</tf>
</tr>
<?php
}
?>
</table>
</form>
<?php echo($_POST['editindex']) ?>
<form name="modeledit" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<input type="hidden" name="selman" value="<?php echo($man_name) ?>"/>
<input type="hidden" name="index" value="<?php echo($_POST['editindex']); ?>"><!-- Get the index of our model to edit -->
<input type="text" name="modelname" value="<?php echo($array[ $_POST['editindex'] ][0]); ?>" /> Modell<br/>
<input type="text" name="modelprice" value="<?php echo($array[ $_POST['editindex'] ][1])?>" /> Pris<br/>
<input type="text" name="modelnocarbon" value="<?php echo($array[ $_POST['editindex'] ][2])?>" /> Utan kartong<br/>
<input type="submit" name="addmodel" value="Edit" />
<!-- ? Add a clear button, so I can add a model after clickng on a Edit field -->
</form>
<?php
}
// vv added to easy read on forum...
?>
So the 2nd form is empty, as it should be.
Now if i click a edit button, it will do this function
Code: Select all
if($_POST['modelindexedit']) {
$showmodels = true;
$man_name = $_POST['selman']; // set var to selected manufacturer stored in form
}
By my understandning, the editindex, should be the $i value of each Edit button, but for some reason, it returns the last $i, so all i can do is edit the last key in the array