472,353 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

dropdown problem

coolv
6
Hello
I have problem in my page that the dropdown box is not displaying data according to selection of first dropdown.Please help me.
Below is my code.

thanks..............
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.     if (!isset($_SESSION['uname'])) {
  5.         header('Location: index.php?msg=acc');
  6.         exit;
  7.     }
  8. ?>
  9. <html>
  10. <head>
  11. <title>Add Main Category</title>
  12. <link rel="stylesheet" href="css/header.css">
  13. <link rel="stylesheet" href="css/footer.css">
  14. <link rel="stylesheet" href="css/misc.css">
  15. <link rel="stylesheet" href="css/nav.css">
  16. </head>
  17. <body>
  18. <table border="0" height="100%" width="100%" cellpadding="0" cellspacing="0">
  19.     <tr>
  20.         <td colspan="2" height="8%"; valign="top">
  21.             <?php include 'templates/header.inc'?>
  22.         </td>
  23.     </tr>
  24.     <tr>
  25.         <td width="10%" valign="top"><br>
  26.           <?php include 'templates/adminmenu.php';?>
  27.         </td>
  28.         <td width="90%" valign="top"><br>
  29.         <?php
  30.            include 'classes/ez_sql.php';
  31.             $page = $_REQUEST['page'];
  32.  
  33.             if(empty($page))
  34.             $page = 'home';
  35.  
  36.             switch($page) 
  37.             {
  38.                 case 'home':
  39.                    showCountry();
  40.                    break;
  41.  
  42.                 case 'add':
  43.                    addCountry();
  44.                    break;
  45.  
  46.                 case 'edit':
  47.                    showEdit();
  48.                    break;
  49.  
  50.                 case 'update':
  51.                    updateCountry();
  52.                    break;
  53.  
  54.                 case 'del':
  55.                    delCountry();
  56.                    break;
  57.  
  58.                 default:
  59.                    showCountry();
  60.             }
  61. function showCountry()
  62. {
  63. ?>
  64. <script language="javascript">
  65. function checkForm()
  66. {
  67.    var ccategory,cmaincat,csubcat;
  68.    with(window.document.frmAdd)
  69.    {
  70.        ccategory = category;
  71.        cmaincat = maincat;
  72.        csubcat = subcat;
  73.    }
  74.    if(trim(cmaincat.value) == '')
  75.    {
  76.       alert('Main Category is required!');
  77.       cmaincat.focus();
  78.       return false;
  79.    }
  80.    else if(trim(ccategory.value) == '')
  81.    {
  82.       alert('Category is required!');
  83.       ccategory.focus();
  84.       return false;
  85.    }
  86.    else if(trim(ccsubcat.value) == '')
  87.    {
  88.       alert('Sub Category is required!');
  89.       csubcat.focus();
  90.       return false;
  91.    }
  92.    else
  93.    {
  94.       ccategory.value = trim(ccategory.value);
  95.       return true;
  96.    }
  97. }
  98.  
  99. function trim(str)
  100. {
  101.    return str.replace(/^\s+|\s+$/g,'');
  102. }
  103. </script>
  104. <script language="javascript">
  105. function sureToDelete(id)
  106. {
  107.     if (confirm("Are you sure to delete this Category?"))
  108.         document.location = "<?php echo basename($_SERVER['PHP_SELF']);?>?page=del&subcat_id="+id ;
  109. }
  110. </script>
  111.  
  112. <form action="<?php echo basename($_SERVER['PHP_SELF']);?>" method="post" name="frmAdd"  enctype="multipart/form-data">
  113.           <table align="center"><tr><td style="color:#CC0000">
  114.           <? if (!empty($_REQUEST['msg'])) 
  115.              {
  116.                 if ($_REQUEST['msg'] == "err")
  117.                 {
  118.                    echo "<h5>";
  119.                    echo "This Category is Already Existed!";
  120.                    echo "</h5>";
  121.                 }
  122.              }
  123.           ?>
  124.           </td></tr></table>
  125.           <table width="46%" height="14%" border="0" cellpadding="3" cellspacing="0" align="center" class="tbord">
  126.             <tr align="center">
  127.               <th colspan="2" valign="top">Add Sub Category</th>
  128.             </tr>
  129.             <tr>
  130.               <td align="right" valign="top" class="tdlabel">Main Category Name :</td>
  131.               <td align="left" valign="top">
  132.               <?
  133.                   $q4=mysql_query("SELECT DISTINCT maincat_id,maincat_name FROM maincategory_master");
  134.                   $maincat=$_GET['maincat'];
  135.  
  136.                   echo "<select name='maincat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
  137.                     while($notici = mysql_fetch_array($q4)) 
  138.                     { 
  139.                       if($notici['maincat_id']==@$maincat)
  140.                     {
  141.                         echo "<option selected value='$notici[maincat_id]'>$notici[maincat_name]</option>"."<BR>";
  142.                     }
  143.                     else
  144.                     {
  145.                         echo  "<option value='$notici[maincat_id]'>$notici[maincat_name]</option>";
  146.                     }
  147.                    }
  148.                   echo "</select>";
  149.           ?>
  150.               </td>
  151.             </tr>
  152.             <tr>
  153.               <td align="right" valign="top" class="tdlabel">Category Name :</td>
  154.               <td align="left" valign="top">
  155.               <?php
  156.             if(isset($maincat) and strlen($maincat) > 0)
  157.             {
  158.                 $quer=mysql_query("SELECT DISTINCT category_name,category_id,maincat_id FROM category_master where maincat_id='$maincat'"); 
  159.             }
  160.             echo "<select name='category' ><option value=''>Select one</option>";
  161.             while($name= mysql_fetch_array($quer)) 
  162.             { 
  163.                 if($name['category_id']==@$cat3)
  164.                 {
  165.                     echo "<option selected value='$name[category_id]'>$name[category_name]</option>"."<BR>";
  166.                 }
  167.                 else
  168.                 {
  169.                     echo  "<option value='$name[category_id]'>$name[category_name]</option>";
  170.                 }
  171.             }
  172.             echo "</select>";
  173.         ?>
  174.               </td>
  175.             </tr>
  176.             <tr>
  177.               <td align="right" valign="top" class="tdlabel">Sub Category Name : </td>
  178.               <td align="left" valign="top"><input type="text" name="subcat"></td>
  179.             </tr>
  180.             <tr align="center">
  181.               <td colspan="2" valign="top"><input name="Insert" type="submit" class="button" value="Insert" onClick="return checkForm()">
  182.                   <input type="hidden" name="page" value="add"></td>
  183.             </tr>
  184.         </table>
  185. <script language="javascript">
  186. function reload3(form)
  187. {
  188. var val=form.maincat.options[form.maincat.options.selectedIndex].value; 
  189. self.location='subcategory.php?maincat=' + val ;
  190. }
  191.  
  192. </script>
  193.         </form>        
  194.         <table width="57%" align="center">
  195.     <?php
  196. $page_name="subcategory.php"; //  If you use this code with a different page ( or file ) name then change this 
  197. $start=$_GET['start'];                                // To take care global variable if OFF
  198. if(!($start > 0)) 
  199. {                         // This variable is set to zero for the first page
  200. $start = 0;
  201. }
  202. $eu = ($start -0);                
  203. $limit = 15;                                 // No of records to be shown per page.
  204. $this1 = $eu + $limit; 
  205. $back = $eu - $limit; 
  206. $next = $eu + $limit;  
  207.  
  208.      $query2="SELECT subcat_id FROM subcat_master";
  209.      $result2=mysql_query($query2);
  210.      echo mysql_error();
  211.      $nume=mysql_num_rows($result2); 
  212.  
  213.        global $db;
  214.         $sql = "SELECT * FROM subcat_master ORDER BY subcat_name limit $eu, $limit ";
  215.         if($countreis = $db->get_results($sql))
  216.          {
  217. ?>
  218.         <tr>
  219.           <th align="center">Main Category Name</th>
  220.           <th align="center">Category Name</th>
  221.           <th align="center">Sub Category Name</th>
  222.           <th align="center" colspan="2">Operations</th>
  223.         </tr>
  224.     <?php 
  225.               $odev = 1;
  226.               foreach($countreis as $country)
  227.               {
  228.                   $q1="select maincat_name from maincategory_master where maincat_id='$country->maincat_id'";
  229.                 $main=$db->get_var($q1);
  230.                 $q2="select category_name from category_master where category_id='$country->category_id'";
  231.                 $cate=$db->get_var($q2);
  232. ?>
  233.     <tr class="<?php if($odev % 2) echo 'TrOdd'; else echo 'TrRows';?>">
  234.           <td><?php echo $main;?></td>
  235.           <td><?php echo $cate;?></td>
  236.           <td><?php echo $country->subcat_name;?></td>
  237.           <td align="center">
  238.             <a href="<?php echo basename($_SERVER['PHP_SELF']).'?page=edit&subcat_id='.$country->subcat_id;?>" class="link">Edit            </a></td>
  239.           <td align="center">
  240.             <a href="javascript:sureToDelete(<?php echo $country->subcat_id;?>)" class="link">Delete</a></td>
  241.         </tr>    
  242. <?php
  243.                 $odev++;
  244.             }
  245.         } else{
  246.         ?>
  247.         <tr><td><?
  248.             echo 'No record found!';
  249.             ?></td></tr><? } 
  250. ?>  
  251.       </table>   
  252. <?php
  253. $p_limit=60; // This should be more than $limit and set to a value for whick links to be breaked
  254. $p_f=$_GET['p_f'];                                // To take care global variable if OFF
  255. if(!($p_f > 0)) 
  256. {                         // This variable is set to zero for the first page
  257. $p_f = 0;
  258. }
  259. $p_fwd=$p_f+$p_limit;
  260. $p_back=$p_f-$p_limit;
  261. //////////// End of variables for advance paging ///////////////
  262. /////////////// Start the buttom links with Prev and next link with page numbers /////////////////
  263. echo "<table align = 'center' width='50%'><tr><td  align='left' width='20%'>";
  264. if($p_f<>0)
  265. {
  266. print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='1' Color='SteelBlue'>PREV $p_limit</font></a>"; 
  267. }
  268. echo "</td><td  align='left' width='10%'>";
  269. //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
  270. if($back >=0 and ($back >=$p_f))
  271. print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='1' Color='DarkBLue'>PREV</font></a>"; 
  272. //////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
  273. echo "</td><td align=center width='30%'>";
  274. for($i=$p_f;$i < $nume and $i<($p_f+$p_limit);$i=$i+$limit)
  275. {
  276. if($i <> $eu)
  277. {
  278. $i2=$i+$p_f;
  279. echo " <a href='$page_name?start=$i&p_f=$p_f'><font face='Verdana' size='1' Color='SteelBlue'>$i</font></a> ";
  280. }
  281. else
  282.  { 
  283.  echo "<font face='Verdana' size='2' Color='DarkBlue'>$i</font>";
  284.  }        /// Current page is not displayed as link and given font color red
  285.  
  286. }
  287. echo "</td><td  align='right' width='10%'>";
  288. ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
  289. if($this1 < $nume and $this1 <($p_f+$p_limit)) 
  290. print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='1' Color='DarkBlue'>NEXT</font></a>";} 
  291. echo "</td><td  align='right' width='20%'>";
  292. if($p_fwd < $nume)
  293. {
  294. print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='1' Color='DarkBlue'>NEXT $p_limit</font></a>"; 
  295. }
  296. echo "</td></tr></table>";
  297. }
  298. function addcountry()
  299. {
  300.     global $db;
  301.     $maincat = $_POST['maincat'];
  302.     $category=$_POST['category'];
  303.     $subcat=ucwords($_POST['subcat']);
  304.     $sql="select maincat_id,category_id,subcat_name from subcat_master where maincat_id='$maincat' and category_id='$category' and subcat_name='$subcat'";
  305.     $cat=$db->get_row($sql);
  306.     if($cat->maincat_id && $cat->category_id && $cat->subcat_name)
  307.     {
  308.         echo "<script language='javascript'>";
  309.             echo "window.location='subcategory.php?msg=err'";                   
  310.             echo "</script>";    }
  311.     $q1="insert into subcat_master(maincat_id,category_id,subcat_name) values('$maincat','$category','$subcat')";
  312.     $db->query($q1);
  313.     echo '<script language="javascript">document.location="'.basename($_SERVER['PHP_SELF']).'";</script>'."\n";
  314. }
  315. function showEdit()
  316. {
  317.     global $db;
  318.     $id = $_REQUEST['subcat_id'];
  319.  
  320.     $sql = "SELECT maincat_id,category_id,subcat_name FROM subcat_master WHERE subcat_id = '$id'";
  321.     $cname = $db->get_row($sql);
  322.     $q1="select maincat_name from maincategory_master where maincat_id='$cname->maincat_id'";
  323.     $main=$db->get_var($q1);
  324. ?>
  325.  
  326.  
  327. <form action="<?php echo basename($_SERVER['PHP_SELF']);?>" method="post" name="frmEdit" enctype="multipart/form-data">
  328. <script language="javascript">
  329. function checkForm()
  330. {
  331.    var ccategory,csubcat;
  332.    with(window.document.frmEdit)
  333.    {
  334.        ccategory = category;
  335.  
  336.        csubcat = subcat;
  337.    }
  338.  
  339.    if(trim(ccategory.value) == '')
  340.    {
  341.       alert('Category is required!');
  342.       ccategory.focus();
  343.       return false;
  344.    }
  345.    else if(trim(ccsubcat.value) == '')
  346.    {
  347.       alert('Sub Category is required!');
  348.       csubcat.focus();
  349.       return false;
  350.    }
  351.    else
  352.    {
  353.       ccategory.value = trim(ccategory.value);
  354.       return true;
  355.    }
  356. }
  357.  
  358. function trim(str)
  359. {
  360.    return str.replace(/^\s+|\s+$/g,'');
  361. }
  362. </script>
  363.     <table width="313" align="center" cellpadding="3" cellspacing="0" class="tbord">
  364.         <tr align="center">
  365.             <th colspan="2" class="tbord">Edit Sub Category </th>
  366.         </tr>
  367.             <tr>
  368.               <td align="right" valign="top" class="tdlabel">Main Category Name  :</td>
  369.               <td align="left">
  370.               <? echo $main;?>
  371.                 </td>
  372.           </tr>
  373.             <tr>
  374.               <td align="right" valign="top" class="tdlabel">Category Name  :</td>
  375.               <td align="left">
  376.               <?php
  377.  
  378.                 $q2=mysql_query("SELECT DISTINCT category_name,category_id FROM category_master");
  379.  
  380.                 echo "<select name='category'><option value=''>Select one</option>";
  381.                 while($noticia2 = mysql_fetch_array($q2)) 
  382.                 { 
  383.                     if($noticia2['category_id']==$cname->category_id)
  384.                     {
  385.                         echo "<option selected value='$noticia2[category_id]'>$noticia2[category_name]</option>"."<BR>";
  386.                     }        
  387.                     else
  388.                     {
  389.                         echo  "<option value='$noticia2[category_id]'>$noticia2[category_name]</option>";
  390.                     }
  391.                 }
  392.                 echo "</select>";
  393.             ?>
  394.  
  395.               </td>
  396.           </tr>
  397.             <tr>
  398.               <td align="right" valign="top" class="tdlabel">Sub Category Name : </td>
  399.               <td align="left"><input type="text" name="subcat" value="<? echo $cname->subcat_name;?>"></td>
  400.             </tr>
  401.         <tr align="center">
  402.             <td colspan="2">
  403.               <input type="hidden" name="page" value="update">
  404.               <input type="hidden" name="subcat_id" value="<?php echo $id;?>">
  405.               <input type="submit" value="Update" class="button" name="update" onClick="return checkForm()">
  406.             <input type="button" value="Back" onClick="document.location='<?php echo basename($_SERVER['PHP_SELF']);?>'" class="button">        </td>
  407.         </tr>
  408.     </table>
  409. <script language="javascript">
  410. function reload2(form)
  411. {
  412.  
  413. var val=form.main1.options[form.main1.options.selectedIndex].value; 
  414. self.location='subcategory.php?page=edit&main1=' + val ;
  415. }
  416.  
  417. </script>
  418.         </form>       
  419.       <?php
  420.     }
  421.   function updatecountry()
  422.     {
  423.         global $db;
  424.         $id=$_REQUEST['subcat_id'];
  425.         $category=$_POST['category'];
  426.         $subcat = ucwords($_POST['subcat']);
  427.         $sql="select category_id,subcat_name from subcat_master where maincat_id='$maincat' and category_id='$category' and subcat_name='$subcat'";
  428.         $cat=$db->get_row($sql);
  429.         if($cat->category_id && $cat->subcat_name)
  430.         {
  431.             header('Location: '.basename($_SERVER['PHP_SELF']).'?msg=err');
  432.             exit;
  433.         }
  434.         $q1="update subcat_master set category_id='$category',subcat_name='$subcat' where subcat_id='$id'";
  435.         $db->query($q1);
  436.         echo '<script language="javascript">document.location="'.basename($_SERVER['PHP_SELF']).'";</script>'."\n";
  437.     }
  438.    function delcountry()
  439.    {
  440.            global $db;
  441.         $id=$_REQUEST['subcat_id'];
  442.         $sql ="delete FROM subcat_master WHERE subcat_id= '$id'";
  443.         $db->query($sql);
  444.         echo '<script language="javascript">document.location="'.basename($_SERVER['PHP_SELF']).'";</script>'."\n";
  445.    } 
  446. ?>
  447. </td>
  448.     </tr>
  449.     <tr>
  450.         <td colspan="2" height="2%" valign="top">
  451.             <?php include 'templates/footer.inc'?>
  452.         </td>
  453.     </tr>
  454. </table>
  455. </body>
  456.  
  457. </html>
  458.  
Dec 22 '08 #1
2 2112
pbmods
5,821 Expert 4TB
Heya, Coolv.

Have you been able to narrow down the problem at all? That's an awful lot of code that you posted.
Dec 23 '08 #2
blyxx86
256 100+
Can you verify that the SQL used returns the two columns requested?

I believe this is the SQL in question
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT maincat_id,maincat_name FROM maincategory_master
  2.  
Also, is the first drop down echoing anything? Even the first "Select one" option?
Dec 29 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm...
1
by: news | last post by:
Hello, I need help with the following problem: An HTML page that have two dropdown list whit different values: 1. Dropdown list...
2
by: ahoodless | last post by:
hi i have a problem that I have tried desperately to tackle but cannot seem to complete. basically i am trying to create a form with three dropdown...
0
by: Manish | last post by:
Hi All, I'm having this problem I hope someone can help provide a solution for it :) I've this dropdown list box in a usercontrol which I'm...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was...
2
by: Brian | last post by:
Hi, All, I have two dropdown lists in itemtemplate in a datagrid. for example, dropA and dropB. also, for the dropdown, I set < Runat="server"...
3
by: devNorway | last post by:
I have been struggling with a problem for days now, and searched for related problems and solutions but had no luck. I have two dropdown...
2
by: William Youngman | last post by:
We are developing an application that presents data to the user in a gridview and we are using the dropdown extender to give the user a SharePoint...
13
by: Shutey | last post by:
I have a strange issue with dropdowns. Using php4, mySQL5, Apache 2 on a fast XP pro PC, I have a form which requires 5 dropdowns populated with...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.