Jump to content

Multiple Select Requirements


rvdb86

Recommended Posts

Hi, I am stuck on bit of a logical/php problem.

 

i am creating a system where the user can create multiple categories which have multiple pages

 

I have three tables:

 

tbl_categories:                                          tbl_pages:

---------------------------------------        -------------------------------------------

| cat_id (INT)  |  cat_name (VARCHAR  |      | page_id (INT)  |  page_name (VARCHAR)  |

----------------------------------------      -------------------------------------------

 

pages_to_categories:

-----------------------------------------------------

|  rel_id(INT)  |  rel_page (INT) |  rel_category (INT) |

------------------------------------------------------

 

the "pages_to_categories" table creates the relationship between the pages and categories as many pages can have many categories.

 

The results are displayed on a page as such:

 

Category x:

    page n

    page n

 

category z:

    page o

  page n

 

under each category there is a drop down list where the user can choose the pages to add to the category.

I created the following code to show pages that are not in the category in the dropdown list:

$query_rel = "SELECT * FROM pages_to_categories WHERE rel_category = '$category_id'";
                    $result_rel = mysql_query($query_rel)
                        or die ("Couldn't execute query");
					$count_rel=mysql_num_rows($result_rel);
				$rel_num = 0;	
                    while ($row_rel = mysql_fetch_array($result_rel))
                    {
				$rel_num++;	

				extract($row_rel);



				$query_page = "SELECT $page_id FROM tbl_pages WHERE page_id = '$rel_page'";
                    $result_page = mysql_query($query_page)
                        or die ("Couldn't execute query");
					$count_page=mysql_num_rows($result_page);
				$page_num = 0;	
                    while ($row_page = mysql_fetch_array($result_page))
                    {
				$page_num++;	
					extract($row_page);
                      echo "<option value="$page_id">$page_name</option>                    
}
                  }

 

the problem with this code is that if the page is in multiple categories it will still show in the dropdown list.

 

I know my post is long and i really appreciate anyone who had the patients to read up to here. Any suggestions would be really appreciated!

Link to comment
https://forums.phpfreaks.com/topic/148135-multiple-select-requirements/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.