Results 1 to 4 of 4

Thread: switch

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    switch

    Hi have this code working on my site but I want it to detect and switch from a sql query.. can this be done?


    PHP Code:
    <select name="club_id">
            <?php

            
    switch ($club_id)
            {
                case 
    "2":
                    
    $opt2 " selected ";
                    break;
                case 
    "3":
                    
    $opt3 " selected ";
                    break;
                case 
    "4":
                    
    $opt4 " selected ";
                    break;
                case 
    "5":
                    
    $opt5 " selected ";
                    break;
                case 
    "6":
                    
    $opt6 " selected ";
                    break;
                case 
    "8":
                    
    $opt8 " selected ";
                    break;
                case 
    "9":
                    
    $opt9 " selected ";
                    break;
                

            }

        
    ?>

          <option <?php echo $opt2?> value="2">Auckland</option>
                      
        </select>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Can you possibly explain a little more. I don't really understand what you mean.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139
    Originally posted by visualAd
    Can you possibly explain a little more. I don't really understand what you mean.
    sure, I the code I posted does a query from the sql database and switches the drop down box!!

    However I have added all the option by hand, I want it to do this for all options on my table... would a loop work?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The usual way is
    PHP Code:
    for($i 0$i count($options); ++i) {
      echo 
    "<option value=\"$i\"".($club_id == $i ' selected="selected"' '').
        
    '>'.$options[$i]."</option>\n";

    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width