Problem med foreach selection!
Er en, som ved, hvordan man kan finde den rigtige image_id til at blive selected? For hver gang jeg updater, så ryger det forvalgte image_id.<?php
$link = mysql_connect("localhost", "designunltdd", "6J6Md9bb")
or die("Could not connect: " . mysql_error());
mysql_select_db('designunltddk_shop', $link)
or die ( mysql_error());
$imagessql = "SELECT * FROM images";
$result = mysql_query($imagessql)
or die("Invalid query: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
$images[$row['image_id']] = $row['image_caption'];
}
switch ($_GET['action']) {
case "edit":
$productssql = "SELECT * FROM products
WHERE products_prodnum = '" . $_GET['id'] . "'";
$result = mysql_query($productssql)
or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array($result);
$products_imageurl = $row['products_imageurl'];
break;
default:
$products_imageurl = "";
break;
}
?>
<select name="products_imageurl" size="1">
<option value="<?php echo $products_imageurl; ?>" selected>Vælg et billede...</option>
<?php
foreach ($images as $image_id => $image_caption) {
if ($image_id == $products_imageurl) {
$selected = " selected";
} else {
$selected = "";
}
?>
<option value="<?php echo $image_id; ?>.jpg"<?php
echo $selected; ?>><?php echo $image_id; ?>.jpg</option>
<?php
}
?>
</select></td>
<td colspan="2" valign="top"><?php
$link = mysql_connect("xxxxx", "xxxxx", "xxxxx")
or die("Could not connect: " . mysql_error());
mysql_select_db('xxxxx_shop', $link)
or die ( mysql_error());
$imagessql = "SELECT * FROM images";
$result = mysql_query($imagessql)
or die("Invalid query: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
$images[$row['image_id']] = $row['image_caption'];
}
switch ($_GET['action']) {
case "edit":
$productssql = "SELECT * FROM products
WHERE products_prodnum = '" . $_GET['id'] . "'";
$result = mysql_query($productssql)
or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array($result);
$products_thumbnailimageurl = $row['products_thumbnailimageurl'];
break;
default:
$products_thumbnailimageurl = "";
break;
}
?>
<select name="products_thumbnailimageurl" size="1">
<option value="<?php echo $products_thumbnailimageurl; ?>" selected>Vælg et billede...</option>
<?php
foreach ($images as $image_id => $image_caption) {
if ($image_id == $products_thumbnailimageurl) {
$selected = "$products_thumbnailimageurl";
} else {
$selected = "";
}
?>
<option value="<?php echo $image_id; ?>.jpg"<?php
echo $selected; ?>><?php echo $image_id; ?>.jpg</option>
<?php
}
?>
</select>
