Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Hey there,

    I am trying to have a page where they can change how it gets the info by using a drop down. Is that possible? Heres what I have come up with.

    Drop Down Menu Names & Values

    A-Z Decending??
    PHP Code:
    $results mysql_query("SELECT * FROM artists ORDER BY bandName LIMIT $page$limit"); 
    Z-A Ascending??
    PHP Code:
    $results mysql_query("SELECT * FROM artists ORDER BY bandName LIMIT $page$limit"); 
    City
    PHP Code:
    $results mysql_query("SELECT * FROM artists ORDER BY city LIMIT $page$limit"); 
    State
    PHP Code:
    $results mysql_query("SELECT * FROM artists ORDER BY state LIMIT $page$limit"); 
    Genre1
    PHP Code:
    $results mysql_query("SELECT * FROM artists ORDER BY genre1 LIMIT $page$limit"); 
    Genre2
    PHP Code:
    $results mysql_query("SELECT * FROM artists ORDER BY genre2 LIMIT $page$limit"); 
    Then in the spot where the code is suppose to be can I put the value of the form?

    Please help me and anything you can tell me is greatly appreciated.

    THANKS!
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  2.  

  3. #2
    Senior Member visualAd's Avatar
    Join Date
    Jan 2003
    Location
    Slough, UK
    Posts
    201
    Member #
    434
    Your queries are correct. Except when you want to sort a the results in descending order, you need to add the word DESc to your query:
    PHP Code:
     $results mysql_query("SELECT * FROM artists ORDER BY bandName DESC LIMIT $page$limit"); 
    You will need to have your HTML look something like this:
    HTML Code:
    <form action="processing_script.php" method="get">
      <select name="action">
        <option value="band_name">Band Name</option>
        <option value="city">City</option>
      </select>
    </option>
    
    Order:
    <select name="order">
      <option value="ASC">Ascending</option>
      <option value="DESC">Descending</option>
    </select>
    Your proccesing script can then check the value of these variables and construact the query appropriatly:
    PHP Code:
    if (isset($_GET['action')) {
      switch (
    $_GET['action']) {
        case 
    'band_name':
          
    $field 'bandName';
          break;
        case 
    'city':
          
    $field 'city';
          break;
        default:
          
    // invalid option - set a default here or something
      
    }

      
    $order 'ASC';

      if (isset(
    $_GET['order']) && $_GET['order'] == 'DESC') {
            
    $order 'DESC';
      }

      
    $query mysql_query("SELECT * FROM artists ORDER BY $field $order LIMIT $page$limit"); 


  4. #3
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    Quote Originally Posted by visualAd
    <form action="processing_script.php" method="get">
    whats the processing_script.php? What do I do with that?
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    That is the action attribute of your form. You can either separate the HTML file and the PHP file (like visualAd has) or use action="<?php echo $PHP_SELF ?>" and have that php in the same file as the HTML form.

    I normally put it in the same file, but if you are maybe going to use this same file (processing_script.php) on 2 or more pages, have it as it's own file as this will save duplicating code.

  6. #5
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    is there anyway you can help me w/ that? I dont see u on MSN anymore.
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  7. #6
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well, all you would have to do is copy the code visualAd gave, save it as processing_script.php (or whatever you wish with a .php extension) and change your action attribute to match what you call it.

  8. #7
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    i did but i got a no go, but i added more options so would I have to add those to the processing_script.php?

    You know my MSN :P
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  9. #8
    Senior Member visualAd's Avatar
    Join Date
    Jan 2003
    Location
    Slough, UK
    Posts
    201
    Member #
    434
    Yes - you need to add your own options. Understand the code and customize it as required

    In general it is better to submit input to a dedicated processing script and should there be an error in the script, redirect back to the page which generates the form. This enables you to draw a clen line between the parts of you application which produce output and those which accept input.

  10. #9
    Member ThePhoenix2006's Avatar
    Join Date
    Mar 2005
    Location
    Michigan
    Posts
    88
    Member #
    9431
    I will try to customize it but I want to let you know im a newbie at this so i might need some1 to check it. I usually figure the errors out by process of elimination but some are tough.

    Thanks for the help!

    For those who want to help me my MSN is : thephoenix2006@hotmail.com

    Thanks again!
    "Make sure the juice is worth the squeeze" ~The Girl Next Door

  11. #10
    Senior Member visualAd's Avatar
    Join Date
    Jan 2003
    Location
    Slough, UK
    Posts
    201
    Member #
    434
    Post any problems you get here - I'll be happy to help


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com