Advertisement

03.02.2008 at 04:12AM PST, ID: 23207341
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Category Drop Down Display - Option "Selected" from another table.
Tags: PHP, MYSQL
I'm trying to get the dropdown menu to know what category is already selected, when it's being called, and apply "SELECTED" on that option.

This is the function that displays the Drop down menu, and the different options within it, based on what's in the table "kategorier".

The table consists of three columns: ID, parentID, tittel,

The drop down menu is called within a form, that has other fields based on the table "animal".

Now what I need to do is to use the mysql JOIN function to check if the: 'field tittel' in "kategorier" == 'field kategori' in "animal". If true, apply "selected".

The thing is, I can't seem to make it work. Therefor I've cleaned up the code, so it just simply displays all "categorys".

I'm very greateful for any help here.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
function generate_list($parentid) {
 
      $check = false;
 
      $query = mysql_query("SELECT * FROM kategorier WHERE parentID=".$parentid) or die(mysql_error());
      
      while($row = mysql_fetch_object($query)) {
            
            $check_child = mysql_query("SELECT * FROM kategorier WHERE parentID=".$row->ID) or die(mysql_error());
			
		
 
            if(mysql_num_rows($check_child)) {
                  
                  print "<option name='".$row->tittel."'  label='".$row->tittel."'>";
				  print $row->tittel;
                  print "</option>";
                  generate_list($row->ID);
                  
 
                  
            }else{
				  
                  print " <option name='".$row->tittel."'  value='$row->ID'>&nbsp;&nbsp;&nbsp;&nbsp;".$row->tittel."</option>";
            
            }
      }
}
 
the call within the form: 	
 
print "Kategori : <SELECT NAME=\"kategori\">";
generate_list(0);
print "</SELECT><br>";
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: gladideg
Solution Provided By: gladideg
Participating Experts: 1
Solution Grade: A
Views: 36
Translate:
Loading Advertisement...
03.02.2008 at 05:19AM PST, ID: 21025883

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.02.2008 at 06:47AM PST, ID: 21026121

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.02.2008 at 01:08PM PST, ID: 21027584

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.03.2008 at 01:32AM PST, ID: 21029994

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.03.2008 at 02:09AM PST, ID: 21030145

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.02.2008 at 05:19AM PST, ID: 21025883
what about teh selected field in the table kategrioir or whatever you call it ?


you have not said anything about the table and the selected values in it .

have you tried something like msgbox upon the id = id ?

where you obtain the selected value from the table ?

waiting for your reply
Assisted Solution
 
03.02.2008 at 06:47AM PST, ID: 21026121
I have a from that reads from the table: Animal:

ID|Name|Colour|Age|Kategori
--------------------------
1|Arny|Blue|44|Blue Parrots
2|Leeroy|Red|11|Dogs
3|Amma|Yellow|13|Fish

And a table that lists the different categories: (Kategorier)

ID|parentID|tittel
---------------------
1|0|Parrots
2|1|Blue Parrots
3|1|Green Parrots
4|1|Yellow Parrots
5|0|Dogs
5|5|Brown dogs
6|0|Fish
7|6|Yellow fish
8|6|Green fish

The category drop down menu currently lists everything in the table: Kategorier.

When it lists everything from that table, it will put the <option "Selected"...></option> tag, and not just <option></option>.

This way, when the "edit" page that calls this function, the user will see that the menu, f.ex allready have "targeted" 2|1 ie. Blue Parrot, because that's whats in the ANIMAL table at the last column called "Kategori".

My code may be a litle bit wrongly built up for this purpose, but I hope you understand what I try to explain.

Thank you for your attention.
 
03.02.2008 at 01:08PM PST, ID: 21027584
i am sorry but i got lost with those animals and categories.

can you simply state it like . i have a 2 tables and a function to generate a drop down menu. when the .... then .... and the problem is.

like for example i want to generate the drop down menu with all the fields in the second table having the selected value as the last value in the first table !!

or something like that .

because i neither understand what are you doing or what is the problem. thanks for your patient.

waiting for your reply
 
03.03.2008 at 01:32AM PST, ID: 21029994
Thank you for your answer. I apologize not to be clear enough, but it's a bit difficult to explain my problem. I'm gonna try again, and now sumarize the whole problem.

I have a EDIT page with 6 text fields and 1 dropdown menu. The 6 text fields are from one table, and the dropdown menu is from another table. When submit is pressed, the values are updated in only the first table, since the second table only contains the menu/category structure.

The edit page is supposed to read from that latter table, to correctly assign the value "SELECTED" to the option that EQUALS to what is in the table of what is opened. Further explanation below:

When a EDIT page is called with $_GET (ie. edit.php?name=leeroy), the content of the row with "leeroy" is called into the 6 text fields, AND a function is called, to read from the table with the menu/category structure, and applies the results in a dropdown menu.

I need a way to link the rows in the one table, to the rows in the other table with the function described above.

IE:

Table 1
ID|Name|Surname|Adresse|CATEGORYNAME
2|0|Leeroy|Hansen|Kitchenavenue 5|Album 1

Table 2
ID|parentID|CATEGORYNAME
1|0|Albums
2|1|Album 1
3|1|Album 2

When the Dropdown menu FUNCTION (source above) is called, it reads from Table 2.

If what's in Table1,fieldname ALBUM 1 equals to anything in Table 2, then assign the value "SELECTED" to it.

It's basicly a easy category structure with a drop down menu, and I can't seem to link them together with the code above.

Hope this was clearer.
 
03.03.2008 at 02:09AM PST, ID: 21030145
This is the whole script. Where I*ve almost got it to work now, with the JOIN mysql function.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
<?php
session_start();
 
dbconnect.....
 
 
 
 
function generate_list($parentid) {
 
      $check = false;
 
      $query = mysql_query("SELECT * FROM kategorier WHERE parentID=".$parentid) or die(mysql_error());
 
      
      while($row = mysql_fetch_object($query)) {
            
	  $check_child = mysql_query("SELECT * FROM kategorier WHERE parentID=".$row->ID) or die(mysql_error());
		
	  $sjekka =  mysql_query("SELECT animal.kategori, kategorier.tittel FROM animal, kategorier WHERE animal.kategori=".$row->ID) or die(mysql_error());	
	
	  $selected = ('SELECTED');
 
	  if($sjekka <=0) {
		  return $selected;
	  }
            if(mysql_num_rows($check_child)) {
                  
                  print "<option " . $selected." name='".$row->tittel."'  label='".$row->tittel."'>";
				  print $row->tittel;
                  print "</option>";
				  print  ('heia');
                  generate_list($row->ID);
                  
 
                  
            }else{
				  
				  
                  print " <option " . $selected." name='".$row->tittel."'  value='$row->tittel'>&nbsp;&nbsp;&nbsp;&nbsp;".$row->tittel."</option>";
            
            }
      }
}
 
 
$file_to_be_edited= $_GET["name"];
 
$query  = "SELECT lydid, opprinneligfilnavn, tittel, kortbeskrivelse, kategori, fullurl, infoomfil FROM animal WHERE lydid='$_GET[name]'";
$result = mysql_query($query);
 
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
	print "<FORM METHOD=POST ACTION=\"update.php\">";
	print "<INPUT TYPE=\"hidden\" NAME=\"lydid\" VALUE=\"{$row['lydid']}\">" ;
	print "Opprinnelig filnavn: {$row['opprinneligfilnavn']}<br>" ;
	print "Tittel : <INPUT TYPE=\"text\" NAME=\"tittel\" VALUE=\"BLABLA\"><br>" ;
	print "Kort beskrivelse : <INPUT TYPE=\"text\" NAME=\"kortbeskrivelse\" VALUE=\"{$row['kortbeskrivelse']}\"><br>" ;
 
	print "Kategori : <SELECT NAME=\"kategori\">";
generate_list(0);
	print "</SELECT><br>";
 
	print "Full URL : <INPUT TYPE=\"text\" NAME=\"fullurl\" VALUE=\"{$row['fullurl']}\"><br>";
	print "Informasjon : <INPUT TYPE=\"text\" NAME=\"infoomfil\" VALUE=\"{$row['infoomfil']}\"><br>";
	print "<INPUT TYPE=\"submit\">";
	print "</FORM>" ;
 
}
 
 
?>
Open in New Window
Accepted Solution
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628