Hi,

I have 2 tables i am querying. The first table has 2 columns, one for folder ID and the other for Category ID.

I want to query that table to get a loop of all the folder ID's based on the category ID chosen.

Then i query the second table that holds the folder ID's and Folder Names.

I compare the first tables folder ID results to the second tables folder ID's

My problem is that where i close off my loop i end up with a drop down select box for every result. Its like the query works but the order of it or the closing curly bracket is wrong.

Please Help

<?php 
$queryfolderCat = "SELECT * FROM FoldersCats WHERE cat_id=".$_GET['catid'];
$folderCatresult = mysql_query($queryfolderCat) or die(mysql_error());

while ($rowfolderCat = mysql_fetch_array($folderCatresult)) { // first loop
$folderIdeez = $rowfolderCat['folder_id'];

$queryfolder = "SELECT * FROM Folders WHERE folder_id=".$folderIdeez." ORDER BY folder_name DESC";
$folderresult = mysql_query($queryfolder) or die(mysql_error());
?>

<select  id="folder"  name="folder" > 

<?php 
while ($rowfolder = mysql_fetch_array($folderresult)) { // second loop
$folder = $rowfolder['folder_id'];
$foldername = $rowfolder['folder_name'];
?>

<option selected value="<?php echo $folder;?>" >
<?php echo $foldername;?>
</option>

<?php }} // both loops closed ?> 

</select>

May I suggest that you simply join the two queries to get the result you want

SELECT Folders.folder_name
FROM FoldersCats
Join Folders on Folders.folder_id = FolderCats.folder_id
WHERE Folder.cat_id=".$_GET['catid'
order by Folder.folder_name

Or something pretty close should work

May I suggest that you simply join the two queries to get the result you want

SELECT Folders.folder_name
FROM FoldersCats
Join Folders on Folders.folder_id = FolderCats.folder_id
WHERE Folder.cat_id=".$_GET['catid'
order by Folder.folder_name

Or something pretty close should work

Hi,

Thanks so much for that. I havent tried it yet as i had to move on to something else.
I will however test your code and mark this thread as complete / solved in the next few days.

Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.