Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto fill dropdown list error

    Hi Guys,

    Im using the code below to autofill a dropdown list from my MYSQL DB.
    The only problem is it is leaving out the first entry (alphabetically) for each $vehicle_make ????

    Does anyone know why this may be hapenning?


    PHP Code:
    <select name="vehicle_model" class="textbox"> 
        <option value="">select a type</option>
        <?php 
        
        
    require_once ('../mysql_connect.php');
         
        
    $query mysql_query("SELECT model FROM Vehicles WHERE make='$_GET[vehicle_make]' ORDER BY model");   // autofill dropdown list 'select' with options from DB
        
    $r mysql_fetch_array($query); 

    while(
    $r mysql_fetch_assoc($query)) {
            echo 
    '<option value="'.$r['model'].'">'.$r['model'].'</option>';
        }  
       
        
    ?> 
    </select>
    PHP Code:
    make='$_GET[vehicle_make]' 
    An example of this data is (Honda, Ford, Toyota)

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,063
    Thanks
    2
    Thanked 317 Times in 309 Posts
    The following line of your code fetches a row from the result set, but does not use it.
    PHP Code:
    $r mysql_fetch_array($query); 
    Why are you doing that?
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you have to state the result dont you?

  • #4
    New Coder
    Join Date
    Jul 2006
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got it sorted by removing the line below, thank you

    PHP Code:
    $r mysql_fetch_array($query); 


  •  

    Posting Permissions

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