welsh
11-23-2006, 07:20 PM
hey, im editing the placement of an image in a gallery. right now when i click edit the image, the name, caption, and what gallery it is in appears. i want the gallery to appear in a drop down menu, however i want wat ever gallery it is in to appear first. So say if i had something like the gallerys: christmas, new years and easter. and the picture i was editing was in the new years gallery the drop down menu would be:
new years
christmas
easter
now the code im sort of confused on here what ive got so far:
$group = $_POST['id'];
$connection = mysql_connect($host,$user,$password)
or die ('Couldnt connect: '.$connection.' - Error: '.mysql_error());
$db = mysql_select_db($database, $connection)
or die ('Couldnt select database: '.$db.' - Error: '.mysql_error());
$query = "SELECT * FROM galleryDirect";
$result = mysql_query($query) or die ('Couldnt run query: '.$query.' - Error: '.mysql_error());
echo '<select name="gallery" size=1>';
while($row = mysql_fetch_array($result)){
if ($group == $row['id']) {
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option> \n';
}
while($id != $row['id'] and $row = mysql_fetch_array($result)){
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option> \n';
}
}
echo '</select>';
}
now after reading this code i realized it is extremely flawed. as it run the if statement in every loop! i hope i explained it enough, any help would be great.
new years
christmas
easter
now the code im sort of confused on here what ive got so far:
$group = $_POST['id'];
$connection = mysql_connect($host,$user,$password)
or die ('Couldnt connect: '.$connection.' - Error: '.mysql_error());
$db = mysql_select_db($database, $connection)
or die ('Couldnt select database: '.$db.' - Error: '.mysql_error());
$query = "SELECT * FROM galleryDirect";
$result = mysql_query($query) or die ('Couldnt run query: '.$query.' - Error: '.mysql_error());
echo '<select name="gallery" size=1>';
while($row = mysql_fetch_array($result)){
if ($group == $row['id']) {
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option> \n';
}
while($id != $row['id'] and $row = mysql_fetch_array($result)){
echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option> \n';
}
}
echo '</select>';
}
now after reading this code i realized it is extremely flawed. as it run the if statement in every loop! i hope i explained it enough, any help would be great.