SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: Drop Down Menu

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop Down Menu

    Hi Guys

    I am trying to make this list into a drop down menu, can someone help?

    When you select the the language of choice the presenters will show.

    here is my code for the list:

    PHP Code:
    <?php
        
    include("CMS/config.inc.php");
        
    $images_dir1 'CMS/presenters/photos';
        
    // initialization
        
    $result_array = array();
        
    $counter 0;

        
    $cid = (int)($_GET['cid']);
        
    $pid = (int)($_GET['pid']);

        
    // Category Listing

            
    $number_of_categories_in_row 1;

            
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
                            FROM pdetails_category as c
                            LEFT JOIN pdetails_photos as p ON p.photo_category = c.category_id
                            GROUP BY c.category_id" 
    );
            while( 
    $row mysql_fetch_array$result ) )
            {
                
    $result_array[] = "<a href='./presenters-language.php?cid=".$row[0]."' class='cat_list' alt='".$row[1]."' title='".$row[1]."'>".$row[1]."</a>";
            }
            
    mysql_free_result$result );    

            
    $result_final "<table cellpadding='5' align='left'><tr>\n";

            foreach(
    $result_array as $category_link)
            {
                if(
    $counter == $number_of_categories_in_row)
                {    
                    
    $counter 1;
                    
    $result_final .= "\n</tr>\n<tr>\n";
                }
                else
                
    $counter++;

                
    $result_final .= "\t<td align='left'>".$category_link."</td>\n";
            }

            if(
    $counter)
            {
                if(
    $number_of_categories_in_row-$counter)
                
    $result_final .= "\t<td colspan='".($number_of_categories_in_row-$counter)."'>&nbsp;</td>\n";

                
    $result_final .= "</tr></table>";
            }
            
    // Final Output
    echo <<<__HTML_END
    <div>
      
    $result_final
    </div>    
    __HTML_END;
    ?>
    the output can be found here: eavafm.com/test/presenters.php

    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    What is the problem?

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am trying to make the List of presenter languages into a drop down menu

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Yes, I understand that. Why can't you do it? What is the problem? Do you know how to make a drop down list in HTML?

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guido2004

    Thanks for getting back to me!!

    Here is code but it does not work, as it put the whole array of id's when you click view presenters, can you help?

    PHP Code:
    <?php
        
    include("CMS/config.inc.php");
        
            
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
                            FROM pdetails_category as c
                            LEFT JOIN pdetails_photos as p ON p.photo_category = c.category_id
                            GROUP BY c.category_id" 
    );
            
            while( 
    $row mysql_fetch_array$result ) ) 
            { 
                
    $cat_id .= $row[0];
                
    $category_list .= "<option value='".$row[0]."'>$row[1]</option>\n";
                
                
    $result_final '<form name="view_category" action="presenters-language.php?cid='.$cat_id.'" method="post">
                                  <p>Select Gallery: </p>
                                  <select name="categoryid">'
    $category_list .'</select>
                                  <input type="submit" value="View Presenters" name="action" />
                                 </form> '
    ;
            }
        
    echo <<<__HTML_END
    <div>
      
    $result_final
    </div>    
    __HTML_END;
    ?>

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Put this
    PHP Code:
    $result_final '<form name="view_category" action="presenters-language.php?cid='.$cat_id.'" method="post">
                                  <p>Select Gallery: </p>
                                  <select name="categoryid">'
    $category_list .'</select>
                                  <input type="submit" value="View Presenters" name="action" />
                                 </form> '

    Outside the while loop

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi i have tried that the same thing happens

    my new code:
    PHP Code:
    <?php
        
    include("CMS/config.inc.php");
        
            
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
                            FROM pdetails_category as c
                            LEFT JOIN pdetails_photos as p ON p.photo_category = c.category_id
                            GROUP BY c.category_id" 
    );
            
            while( 
    $row mysql_fetch_array$result ) ) 
            { 
                
    $cat_id .= $row[0];
                
    $category_list .= "<option value='".$row[0]."'>$row[1]</option>\n";
                
                
            }
            
    $result_final '<form name="view_category" action="presenters-language.php?cid='.$cat_id.'" method="post">

                                  <p>Select Gallery: </p>

                                  <select name="categoryid">'
    $category_list .'</select>

                                  <input type="submit" value="View Presenters" name="action" />

                                 </form> '


        
    echo <<<__HTML_END
    <div>
      
    $result_final
    </div>    
    __HTML_END;
    ?>

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    What is the result (HTML code) of that piece of PHP?

  9. #9
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi the output can be found here:

    eavafm.com/test/presenters.php

    as i want it to link here

    eavafm.com/test/presenters-language.php?cid=1

    Thanks

  10. #10
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    I checked eavafm.com/test/presenters.php, and the drop down looks just fine.
    When I choose a language, the next page doesn't show any presenter, but that might be because there isn't, or because the script that should get the presenters doesn't work right.

    One thing though. Are the cid you pass in the query string, and the categoryid you choose in the drop down menu, two different things? Because the value chosen in the drop down menu isn't passed in the query string, but as a form value in the $_POST array (since you use 'post' as the method).

  11. #11
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guido2004

    I managed to get the script to work!! Thanks for your help.

    I re-sturctured the whole code, you might want to have a look:

    PHP Code:
    <?php
        
    include("CMS/config.inc.php");
        
        if( empty(
    $_POST['action']) ) 
        { 
            
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
                                    FROM pdetails_category as c
                                    LEFT JOIN pdetails_photos as p ON p.photo_category = c.category_id
                                    GROUP BY c.category_id" 
    );
            
            while( 
    $row mysql_fetch_array$result ) ) 
            { 
                
    $category_list .= "<option value='".$row[0]."'>$row[1]</option>\n";    
            }
            
            
    mysql_free_result$result );
            
    $category_list '<select name="categoryid">'$category_list .'</select>'
    ?>
    <form name="presenter_form" action="presenters.php" method="post">
      <h1>Our Presenters</h1>
      <p class="text01">Select Presenter Language:</p>
      <?php echo($category_list); ?> 
      <input type="submit" value="View Presenters" name="action" /> 
    </form>
    <?php
                
     

        else 
        { 
            if( 
    strcasecmp($_POST['action'], "View Presenters" )==&& !empty( $_POST['categoryid'] ) ) 
            { 
                 
    $cid $_POST['categoryid'];
                
                 
    $result mysql_query"SELECT category_name FROM pdetails_category WHERE category_id='".addslashes($cid)."'" );
                 list(
    $category_name) = mysql_fetch_array$result );
                 echo 
    "<h1>Our Presenters - $category_name</h1>";
                 
                 
                 
    $result mysql_query"SELECT c.category_id,c.category_name,COUNT(photo_id)
                                    FROM pdetails_category as c
                                    LEFT JOIN pdetails_photos as p ON p.photo_category = c.category_id
                                    GROUP BY c.category_id" 
    );
            
                 while( 
    $row mysql_fetch_array$result ) ) 
                 { 
                   
    $category_list .= "<option value='".$row[0]."'>$row[1]</option>\n";    
                 }
            
                 
    mysql_free_result$result );
            
                 
    $category_list '<select name="categoryid">'$category_list .'</select>'
            
                 
    ?>
                 <form name="presenter_form" action="presenters.php" method="post">
                   <p>Select Presenter Language:</p>
                   <?php echo($category_list); ?> 
                   <input type="submit" value="View Presenters" name="action" /> 
                 </form>
                 <?php
                 
                 $results 
    mysql_query("SELECT photo_id, photo_name, photo_show, photo_description, photo_filename FROM pdetails_photos WHERE photo_category='".addslashes($cid)."' ORDER BY photo_name ASC");
                 
                 while (
    $data mysql_fetch_array($results))
                 {
                   echo(
    "<table class='pre_t'>
                           <tr>
                             <td valign='top' width='110'>
                               <p><img src='CMS/presenters/photos/tb_" 
    .$data[photo_filename]. "' alt='" .$data[photo_name]. "' title='" .$data[photo_name]. "' class='thumb_l' /></p>
                             </td>
                             <td valign='top'>
                               <p class='photo_name'>Name: " 
    .$data[photo_name]. "</p>
                               <p class='photo_show'>Show Times: " 
    .$data[photo_show]. "</p>
                               <p class='photo_des'>" 
    .$data[photo_description]. "</p>
                             </td>
                           </tr>
                         </table>"
    );
                 } 
            } 
            else 
            { 
                echo(
    "<p class='text01' align='center'>Action not understood! Please Type in valid Language.</p>" ); exit; 
            } 
        } 
    ?>
    Not sure if it is correct in terms of best practice but i am still learning.

    Please have a look at the output:

    eavafm.com/test/presenters.php

    Also what you think of the site in general?

    Thanks again!!


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
  •