Hey all!
I'm creating a little script in my administration module of my website where I have added a few different categories used in a picture gallery. That works just fine. It also works fine when adding photos to the categories that's already added. But now I'm trying to make an "edit photo script" where I want to make it possible to edit a specific photo and save that to my database and there's a small problem there.
The editing process should include the filename of the photo (which can't be edited) - the photo category (which should be able to be edited) and the placing of the photo (if it's the 1st, 5th or 11th photo in a series in the specified category).
The information popups up just the way it should BUT I get the problems when showing the category the actual photo belongs to.
The tables I use are the following:
::: photos_category
category_ID
category_Name
::: photos
photo_ID
photo_File
photo_Category
photo_Place
It's obvious what happens when I add a category. When I add a photo putting it into a category, the "photo_Category" gets the same ID as category_ID in the other table - that way I can make a reference from the actual photo to the category table to find the right name.
Anyway - when I want to edit a photo I go to an edit-page which brings the photo_ID along as a variable. That way I can select all info from that particular photo - BUT when I want to make a select box to choose the category that's where the problem comes. You see, I want to make a list of all the categories listed in the database (table: photos_category) but I also want the category specified for the actual photo to be selected, so I wouldn't have to edit that in case I just wanted to edit the placement of the photo. But how do I go about and do that?
I posted the code below I use to select everything in photos_category and list it in a select box. "$photo_ID" from the table "photos" has been defined earlier, if that makes it easier to find a solution to my problem. Thanx in advance!
<?
connectDatabase();
$query = "select * from photos_category";
$result = mysql_query($query) or die("".mysql_errno()." Error: ".mysql_error());
?>
<select name="photo_Category" class="form" style="width: 400px;">
<option value=""> < Choose category ></option>
<?
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_array($result))
{
$category_ID = $row['category_ID'];
$category_Name = $row['category_Name'];
?>
<option value="<?= $category_ID ?>"><?= $category_Name ?></option>
<?
}
?>
</select>
<?
}
?>