SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dependent form elements through linking

    I posted a version of this in the php area, whereupon they stated to look in javascript.

    PHP Code:
    <?php
    session_start
    ();

    // is the one accessing this page logged in or not?
    if (!isset($_SESSION['db_islogged_in'])
       || 
    $_SESSION['db_is_logged_in'] !== true) {

       
    // not logged in, move to login page
       
    header('Location: activate.php');
       exit;
    }


    include(
    'connect.php');
      
    error_reporting(E_ALL & ~E_NOTICE);

        
    $uid   $_SESSION['id'];
        
    $se $_SERVER['PHP_SELF']; 
        
    $gcat   $_GET['cat']; 
        
    $gsex $_GET['gen'];
        
    $images_dir '../uploads';
        
    $cap $_SESSION['cap'];
                        
    $result mysql_query"SELECT * FROM user WHERE id='$uid'" );
            list(
    $id$username$password$fullname$email$notes$image) = mysql_fetch_array$result );
            
            
    $resultb mysql_query"SELECT id, title, text  FROM cats WHERE id = '$gcat'" );
            list(
    $idb$title$text) = mysql_fetch_array$resultb );

    ?>        
    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
    <html xmlns='http://www.w3.org/1999/xhtml'>
    <head>
        <title> Your Votes </title>
           <?php include('css.inc');?>
    </head>
    <body> 
    <div id='text' style='position:fixed; left:2%; top:10%; width:75px; z-index:4'>
            <a href='vote.php?id=<?php echo $uid;?>&amp;cat=0'>Vote</a><br />
            <a href='viewvote.php?id=<?php echo $uid;?>&amp;cat=all'>All votes</a><br /> <br />
            <hr noshade='noshade' /><br />
            <b>Categories</b><br />
            <?php
        $cats 
    mysql_query"SELECT id, title, sex FROM cats" );

               
                while( 
    $c_row mysql_fetch_array($cats)) {      
        
    $c_id       $c_row['id'];
        
    $c_title    $c_row['title'];
        
    $c_sex        $c_row['sex'];

            
           echo 
    "<a href='vote.php?id=".$uid."&amp;cat=".$c_id."&amp;gen=".$c_sex."'>".$c_title."</a><br />";
     }
        
    ?>

    </div> 
    <div id='page' style='position:absolute; left:130px; top:10%; width:50%; z-index:4'>
     <?php 
     
    if($gcat != '0'){?>
    <form action='voteadd.php' method='post'>
    <b><?php echo $title;?>:</b><br />
    <?php echo $text;?><br />
    <hr noshade='noshade' align='left' width='75%' />
    <br /><br />
    <label><input type='hidden' name='title' value='<?php echo $gcat;?>' /></label>
    <label><input type='hidden' name='gender' value='<?php echo $gsex;?>' /></label>
         

    <br />
    <label>Name: <?php echo $username;?></label><br />
        


      <?php          
      
    if($gsex == 'M' or $gsex == 'F'){
    $res2 mysql_query"SELECT id, name, photo_name, gender  FROM pics WHERE gender = '$gsex' ORDER BY name" );
        

         
    while( 
    $row2 mysql_fetch_array($res2)) {    
           
    $idpa $row2['id'];
           
    $namea $row2['name'];

           
     echo 
    "<a href='../test2.php?pid=".$idpa."'><img src='".$images_dir."/tb_".$row2['photo_name']."'  border='0' alt='".$namea." ' title='".$namea."' width='93' height='70' /></a><br /> ";     
     echo 
    "<label> <input type='radio' name='rank1' value='".$idpa."' />rank 1</label><br /> ";
     echo 
    "<label> <input type='radio' name='rank2' value='".$idpa."' />rank 2</label><br /> ";
     echo 
    "<label> <input type='radio' name='rank3' value='".$idpa."' />rank 3</label><br /><br /> ";     

    }   }else{   

    $res2 mysql_query"SELECT id, name, photo_name, gender  FROM pics ORDER BY name" );
        

         
    while( 
    $row2 mysql_fetch_array($res2)) {    
           
    $idpa $row2['id'];
           
    $namea $row2['name'];

           
     echo 
    "<a href='test2.php?id=".$idpa."'><img src='".$images_dir."/tb_".$row2['photo_name']."'  border='0' alt='".$namea." ' title='".$namea."' width='93' height='70'/></a><br /> ";     
     echo 
    "<label> <input type='radio' name='rank1' value='".$idpa."' />rank 1</label><br /> ";
     echo 
    "<label> <input type='radio' name='rank2' value='".$idpa."' />rank 2</label><br /> ";
     echo 
    "<label> <input type='radio' name='rank3' value='".$idpa."' />rank 3</label><br /><br /> ";     

    }       }
    ?>

    <input type='hidden' name='id' value='<?php echo $id;?>' />



    <input type='submit' value='SUBMIT' /></p>
    </form>
    <?php
    }else{
    ?>
    Please choose a category on the left to start your voting.
    <?php }?>
                                       
                                   <br /><br />      </div></body></html>


    this is what I have currently; a page filled with about 100+ images/items. The user is to choose an image/item and rank them (this one is 1-3). However...the only setback at the moment is that they are able to choose the same person for all rankings. What I am looking for is a way to link the inputs: if rank 1 is chosen for an image/item, it is not available for the other choices. If rank 1 is not chosen, they cant choose rank 2 or 3,. etc.

    Is this possible? if so, how do I do it?

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,109
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    It's an HTML question actually

    You can group radio buttons together by giving them the same name attribute
    Code:
    <label><input type="radio" name="rank" value="1" />rank 1</label>
    <label><input type="radio" name="rank" value="2" />rank 2</label>
    <label><input type="radio" name="rank" value="3" />rank 3</label>
    Now when you submit the form - $_POST['name'] could be 1,2 or 3 if, of course you are submitting using the POST method.

    Hope it helps

    Off Topic:


    There are much better ways to structure your PHP code than using inline scripting like you have, I've got so much out of Sitepoint's - Object Oriented PHP solutions - it might interest you also.

  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, I know my php could be better....at the moment, Im just running this as a testing page- just to see if I can get things to work

    The problem with grouping the items like that is that I have over 100 images/items that need to be ranked per category (on a scale of 1-3, or 1-5).

    By grouping the buttons, it removes any possibility for me to choose any item as rank 2, if something was rank 1. I guess it would be something with the select options: if you click on a certain state, the other select could be populated by the counties, and then the next could be by cities.

    The only difference is that I am looking to allow it to be linked in such a way where the rank 1 item can not be ranked again in that particular category, but I am able to rank the other items in the following rankings. (hope that makes sense)

    Everything is being sent through post to voteadd.php, which then fits the values (rank1, rank2, rank3) into separate tables to be called up later in another page.

  4. #4
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,109
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    You need to make each radio group have a different name.
    Code:
    <label><input type="radio" name="photo1rank" value="1" />rank 1</label>
    <label><input type="radio" name="photo1rank" value="2" />rank 2</label>
    <label><input type="radio" name="photo1rank" value="3" />rank 3</label>
    
    <label><input type="radio" name="photo2rank" value="1" />rank 1</label>
    <label><input type="radio" name="photo2rank" value="2" />rank 2</label>
    <label><input type="radio" name="photo2rank" value="3" />rank 3</label>

  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see....but wouldn't that defeat the purpose of the last while command?

    meaning that I would have to write everything up?

    There isnt just a function I could add before I press the submit button to check the answers (or even make sure that its not just marked again)?

  6. #6
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,109
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Trust me on this - Javascript is not the technology you want to use here.
    Good stable trustworthy HTML will do the job.

    You could learn how to better stucture your PHP code so that you actually enjoy "writing everything up".

    Create arrays and use the foreach loop, fetch content from the database once at the top of your script and get it into an associative array. Work through these data arrays logically and generate the needed markup. But this belongs in the PHP forum.


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
  •