SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member noizgod's Avatar
    Join Date
    Dec 2001
    Location
    Savannah,Ga
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio boxes in form....

    well in a nutshell here is my problem....

    Ive got a table called bands with fields id,bname,fname,featured....

    bname=band name
    fname=file name

    When featured = 1 then it is the featured band file and will be displayed on the page. Thats not a problem...all that is sorted out.

    Heres the issue...

    I need to make it so I can select a band from a list and make them the featured band....

    so in other words....

    band A is currently featured...I want to make band C the featured band... I want to be able to select band C from a list(radio buttons,dropdown doesnt really matter), but when I select band C, band A and Band B need to have the featured column revert to 0 while band C goes to 1.

    Ive tried this with radio buttons and I can get featured field to update but it changes all the bands to 1 or 0 depending on the selection. Any ideas?

    [COLOR=dark blue]
    Visit[/COLOR] Coastal Rock Productions [COLOR=dark blue]for info on underground hardcore, emo, punk, and metal.
    Contact Me
    | AIM: noizgod | Yahoo: noizgod[/COLOR]

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi noizgod

    I assume it is something to do with your PHP code. Have you tried setting the "featured" column to 0 for all of the bands, and then setting the appropriate (where ID=bandnumber) band's "featured" value to 1.
    Paul Davey
    webmaster for Whitford Church of Christ

  3. #3
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this?
    PHP Code:
    <html>
        <body>
            <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    <?
    for($c 'A'$c 'H'$c++)
    {
        
    $selected = ($c == $_POST['band']) ? 'checked' null;
        echo 
    "<input type='radio' id='band$c' name='band' value='$c$selected onclick='this.form.submit();'/>";
        echo 
    "<label for='band$c'>Band $c</label><br/>\\n";
        if(
    $selected) echo "Text related to band $c<br/>\\n";
    }
    ?>
            </form>
        </body>
    </html>

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, completely missed what you were asking about...

    Use a query like
    "update bands set featured = case id when $id then 1 else 0 end"
    where $id is the value from the radio button


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
  •