Advertisement

03.26.2008 at 07:11AM PDT, ID: 23270412
[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!

7.8

URGENT: Dependent Drop Down

Asked by pertrai1 in PHP and Databases, PHP Scripting Language

Tags:

EE, I am very desperate to figure out why I can't get this to work. I need to have a dependent drop down that will show the categories in the second drop box depending on what parent category is chosen in the main drop down. Here is where I am having problems. I originally set up my table in mysql to hold one subcategory. Now I need to have a subcategory hold a subcategory. I don't know if this is a problem with my current table:

cat_id int(11)
cat_name varchar(30)
cat_parent int(11) default '0'

If it is a main parent category then it is given the value 0 for cat_parent. If it is a subcategory then the cat_parent is the cat_id of the parent. How can I do this with adding a second subcategory and have the stupid drop downs work. This is getting frustrated because I am trying to learn but the curve it hard. The code I have attached works in getting the parent category and the subcategory. But if the parent is a subcategory it will not get the sub category of the sub category. If I have confused you it is because I am confused. Sorry if I have not provided enough for help.

Thank you in advance for help.

RobStart Free Trial
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:
<?
$query = "SELECT * FROM tblCategories where cat_parent=0";
if (!($result_main=mysql_query($query))) {
  // query failed. report and ...
  die();
}
$mainid = (integer)$_GET['cat_id'];
if ($mainid > 0) {
  $mainid = mysql_real_escape_string($mainid);
  $query = "SELECT * FROM tblCategories WHERE cat_parent='$mainid'";
  if (!($result_sub=mysql_query($query))) {
    // query failed. report and ...
    die();
  }
} else { $result_sub = false; }
?>
 
                      <td>Main Category:</td>
                      <td align="left"><select name="cat_parent" class="inputbox" id="cat_parent">
                        <?
  while ($row=mysql_fetch_assoc($result_main)) {
    echo "<option value=\"{$row['cat_id']}\"",
        (($row['cat_id']==$mainid)?" selected=\"selected\"":''),
        ">{$row['cat_name']}</option>\n";
  }
?>
 
                      </select>                      </td>
                    </tr>
                    <tr>
                      <td>Sub Category:</td>
                      <td align="left"><select name="cat_id" class="inputbox" id="cat_id">
                      <?
if (($mainid > 0) && ($result_sub)) {
  while ($row=mysql_fetch_assoc($result_sub)) {
    echo "<option value=\"{$row['cat_id']}\"",
        (($row['cat_id']==$mainid)?" selected=\"selected\"":''),
        ">{$row['cat_name']}</option>\n";
  } 
} 
?>
[+][-]03.26.2008 at 07:49AM PDT, ID: 21212190

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.26.2008 at 08:29AM PDT, ID: 21212673

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language
Tags: php and databases
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.26.2008 at 09:27AM PDT, ID: 21213387

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.26.2008 at 12:30PM PDT, ID: 21215268

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.27.2008 at 09:26AM PDT, ID: 21223168

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628