Multiple Choice Radio

Results 1 to 6 of 6
  1. #1
    Novice Nagamasa is offline
    MemberRank
    Apr 2012 Join Date
    3Posts

    Multiple Choice Radio

    Hello community,

    I am creating a radio system of choice.

    I have a worry in the code, can you help me?
    PHP Code:
    <?php
        $id
    $_SESSION['uid'];
        
    $req mysql_query("SELECT * FROM users WHERE id='".$id."' AND radio");
        
    $radio mysql_result($req);
        
        if(
    $radio == 0) { echo 'Radio 0'; }
        elseif(
    $radio == 1) { echo 'Radio 1'; }
        elseif(
    $radio == 2) { echo 'Radio 2'; }
    ?>
    Thanks for your help
    Sorry for my english, i'm french


  2. #2
    Gaby is offline
    MemberRank
    Apr 2013 Join Date
    Viva HollandiaLocation
    1,607Posts

    Re: Multiple Choice Radio

    You're missing something after "AND radio".


  3. #3
    G'nome sayin' Exonize is offline
    MemberRank
    May 2011 Join Date
    Czech RepublicLocation
    517Posts

    Re: Multiple Choice Radio

    SELECT radio FROM users WHERE id='".$id."'

  4. #4
    Novice Nagamasa is offline
    MemberRank
    Apr 2012 Join Date
    3Posts

    Re: Multiple Choice Radio

    Quote Originally Posted by Exonize View Post
    SELECT radio FROM users WHERE id='".$id."'
    I tried that but it shows me "Radio 0" While in the db that I put Radio 2

  5. #5
    Valued Member Troll Hotel is offline
    MemberRank
    Nov 2012 Join Date
    SlovakiaLocation
    144Posts

    Re: Multiple Choice Radio

    Why this code ?
    Code:
     if($radio == 0) { echo 'Radio 0'; }
        elseif($radio == 1) { echo 'Radio 1'; }
        elseif($radio == 2) { echo 'Radio 2'; }
    its useless :P you can better use
    Code:
     echo 'Radio'.$radio;
    Also i dont know if youre asking for how to make the choice of radio but if so then you can easely make it with submit buttons here i made something you may find usefull :p just put the html in tpl or whatever you use :P you also can change the buttons to radio buttons so it looks better :D

    Code:
     <?php 
    if(isset($_POST['radio'])) {
    	$channels = array(1, 2);
    	if(in_array($_POST['radio'], $channels)) {
    	    mysql_query("UPDATE users SET radio = '"$_POST['radio']"' WHERE id = '"$id"' ");
    	    echo 'Channel has been changed succesfully to'.$_POST['radio'];
    	} else
    	  exit('This is not an channel!');
    }
    
    ?>
    <html>
    <form method="POST" action="">
    	<input type="submit" name="radio" value="1">
    	<input type="submit" name="radio" value="2">
    	</form>
    </html>
    Last edited by Troll Hotel; 29-07-15 at 01:19 PM.

  6. #6
    Novice Nagamasa is offline
    MemberRank
    Apr 2012 Join Date
    3Posts

    Re: Multiple Choice Radio

    Quote Originally Posted by Troll Hotel View Post
    Why this code ?
    Code:
     if($radio == 0) { echo 'Radio 0'; }
        elseif($radio == 1) { echo 'Radio 1'; }
        elseif($radio == 2) { echo 'Radio 2'; }
    its useless :P you can better use
    Code:
     echo 'Radio'.$radio;
    Normally instead of "0 Radio" "Radio 1" "Radio 2" is the script for the radio display



Advertisement