Er det muligt at opdatere 2 linier i php/mysql samtidigt?
Vil gerne have at den opdatere kolonnen position i to rækker.
Dette virker ikke:
print "Her kan du ændre menuen<br />";
print "<table align='left'>";
$last = mysql_query("SELECT position FROM site ORDER BY position DESC LIMIT 1");
$last2 = mysql_fetch_assoc($last);
$first = mysql_query("SELECT position FROM site ORDER BY position aSC LIMIT 1");
$first2 = mysql_fetch_assoc($first);
if($_GET['position'] != "" and $_GET['action'] == "op" or $_GET['action'] == "ned") {
if($_GET['action'] == "op") {
$op = $_GET['position'] -1;
mysql_query("UPDATE site SET position = '".$op."' WHERE position = '".$_GET['position']."'");
mysql_query("UPDATE site SET position = '".$_GET['position']."' WHERE position = '".$op."'");
}
elseif($_GET['action'] == "ned") {
$ned = $_GET['position'] +1;
mysql_query("UPDATE site SET position = '".$ned."' WHERE position = '".$_GET['position']."'");
mysql_query("UPDATE site SET position = '".$_GET['position']."' WHERE position = '".$ned."'");
}
}
$result = mysql_query("SELECT `id`,`name`, `position` FROM `site` ORDER BY position ASC");
if (!$result) print "Der er sket en fejl";
while ($row = mysql_fetch_assoc($result)) {
if($row['position'] == "1"){
$down = $row['position']+1;
print('
<tr>
<td>
'.$row['name'].'
</td>
<td>
</td>
<td>
<a href="?side=editmenu&position='.$row['position'].'&action=ned">
<img src="images/down.gif" border="0">
</a>
</td>
</tr>');
}
elseif($row['position'] != "1" and $row['position'] != $last2['position']){
print('
<tr>
<td>
'.$row['name'].'
</td>
<td>
<a href="?side=editmenu&position='.$row['position'].'&action=op">
<img src="images/up.gif" border="0">
</a>
</td>
<td>
<a href="?side=editmenu&position='.$row['position'].'&action=ned">
<img src="images/down.gif" border="0">
</a>
</td>
</tr>');
}
elseif($row['position'] == $last2['position']){
print('
<tr>
<td>
'.$row['name'].'
</td>
<td>
<a href="?side=editmenu&position='.$row['position'].'&action=op">
<img src="images/up.gif" border="0">
</a>
</td>
<td>
</td>
</tr>');
}
}
print "</table>";
?>
Håber på hjælp, men prøver selv at arbejde videre på det