Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: fix my php code

  1. #1
    Join Date
    May 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default fix my php code

    Can someone please help me fix my code?
    I can get the first two drop down menus to work but the third (subcategory2)wont display any information...

    Code:
    <?
        
         header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
         header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
         header ("Cache-Control: no-cache, must-revalidate");
         header ("Pragma: no-cache");
         
         header("content-type: application/x-javascript; charset=tis-620");
         
         $data=$_GET['data'];
         $val=$_GET['val'];
         
    $dbhost = "????????????";
    $dbuser = "????????????";
    $dbpass = "????????????";
    $dbname = "????????????";
    mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");  
         
         if ($data=='category') { 
              echo "<select name='category' onChange=\"dochange('subcategory', this.value)\">\n";
              echo "<option value='0'>==== Category ====</option>\n";
              $result=mysql_db_query($dbname,"select `cat_id`, `category` from category order by `category`");
              while(list($cat_id, $category)=mysql_fetch_array($result)){
                   echo "<option value=\"$cat_id\" >$category</option> \n" ;
              }
         } else if ($data=='subcategory') {
              echo "<select name='subcategory' onChange=\"dochange('subcategory2', this.value)\">\n";
              echo "<option value='0'>======== Subcategory ========</option>\n";
              $val2=$val;
              $val = substr($val,0,2);                                 
              $result=mysql_db_query($dbname,"SELECT `cat_id`, `subcategory` FROM subcategory WHERE 'cat_id' != '$val2' AND cat_id LIKE '$val%'  ORDER BY 'subcategory' ");
              while(list($cat_id, $subcategory)=mysql_fetch_array($result)){       
                   echo "<option value=\"$cat_id\" >$subcategory</option> \n" ;
              }
         } else if ($data=='subcategory2') {
              echo "<select  name='subcategory2' >\n";
              echo "<option value='0'>======== Subcategory2 ========</option>\n";
              $val2=$val;
              $val = substr($val,0,4);
              $result=mysql_db_query($dbname,"SELECT `subcat_id` FROM subcategory2 WHERE `subcat_id` != '$val2' AND subcat_id LIKE '$val%' ORDER BY `subcategory2` ");
              while(list($subcat_id, $subcategory2)=mysql_fetch_array($subcategory2)){
                   echo "<option value=\"$subcat_id\" >$subcategory2</option> \n" ;
              }
         }
         echo "</select>\n";  
    ?>

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Is it creating the drop down box with '======== Subcategory2 ========' in it.

  3. #3
    Join Date
    May 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by forum_amnesiac View Post
    Is it creating the drop down box with '======== Subcategory2 ========' in it.
    Thanks for the reply...I dont think so...the first two menus are working fine...and they have the ======= in it too...
    I tried to get rid of it but no luck...

    this is my BD structure if it helps

    category: cat_id - category
    subcategory: subcat_id - cat_id - subcategory
    subcategory2: subcat_id - subcat2

    any idea of why it is not working?

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Without access to your data it is difficult to debug, I did however get the subcategory2 box when I did the following code change to that section.

    PHP Code:
         } else {
             if (
    $data=='subcategory2') {
              echo 
    "<select  name='subcategory2' >\n";
              echo 
    "<option value='0'>======== Subcategory2 ========</option>\n";
              
    $val2=$val;
              
    $val substr($val,0,4);
              
    $result=mysql_db_query($dbname,"SELECT `subcat_id` FROM subcategory2 WHERE `subcat_id` != '$val2' AND subcat_id LIKE '$val%' ORDER BY `subcategory2` ");
              while(list(
    $subcat_id$subcategory2)=mysql_fetch_array($subcategory2)){
                   echo 
    "<option value=\"$subcat_id\" >$subcategory2</option> \n" ;
              }
             } 
    Are you sure that there are some records in the database with 'subcategory2' as their name, if not, then that will be your problem.

    In my test I did hardcode $data to be 'subcategory2'.

  5. #5
    Join Date
    May 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by forum_amnesiac View Post
    Without access to your data it is difficult to debug, I did however get the subcategory2 box when I did the following code change to that section.

    PHP Code:
         } else {
             if (
    $data=='subcategory2') {
              echo 
    "<select  name='subcategory2' >\n";
              echo 
    "<option value='0'>======== Subcategory2 ========</option>\n";
              
    $val2=$val;
              
    $val substr($val,0,4);
              
    $result=mysql_db_query($dbname,"SELECT `subcat_id` FROM subcategory2 WHERE `subcat_id` != '$val2' AND subcat_id LIKE '$val%' ORDER BY `subcategory2` ");
              while(list(
    $subcat_id$subcategory2)=mysql_fetch_array($subcategory2)){
                   echo 
    "<option value=\"$subcat_id\" >$subcategory2</option> \n" ;
              }
             } 
    Are you sure that there are some records in the database with 'subcategory2' as their name, if not, then that will be your problem.

    In my test I did hardcode $data to be 'subcategory2'.
    in my database subcategory2 includes subcat_id and subcat2 with the description of the items I would like to display in the third drop down menu...
    do I need to change something

  6. #6
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Try pasting in the code I posted, to replace from the last 'else if' to 'echo' in your code.

    It may not work but it is a step towards finding the problem.

  7. #7
    Join Date
    May 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by forum_amnesiac View Post
    Try pasting in the code I posted, to replace from the last 'else if' to 'echo' in your code.

    It may not work but it is a step towards finding the problem.
    If I replace the code I get "Category :
    Parse error: syntax error, unexpected $end in /homepages/5/d180349627/htdocs/ajax/locale2.php on line 47"

    and like 47 corresponds to ?>

    any idea why? EDIT I found why...it was missing a } ... no errors now but still no luck with the third menu

    also found another error:
    changed
    Code:
    while(list($subcat_id, $subcategory2)=mysql_fetch_array($subcategory2)){
    to
    Code:
    while(list($subcat_id, $subcategory2)=mysql_fetch_array($result)){
    still no luck...help!

    do you need access to more code? how can I provide you more information to help me work this out?

    let me know...
    Last edited by cherubrock74; 05-12-2009 at 03:20 PM. Reason: fixed code

  8. #8
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Send me some code to create and load a table so I can test your code

  9. #9
    Join Date
    May 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by forum_amnesiac View Post
    Send me some code to create and load a table so I can test your code
    This database will eventually be deleted...so if you want I can private message you the access...
    let me know...

  10. #10
    Join Date
    May 2009
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by forum_amnesiac View Post
    Send me some code to create and load a table so I can test your code
    Can you show me what code you used when you were able to get the subcategory2?
    Also could you show me the DB structure for the data you tested on?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •