SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help to sort a select-form out...

    Heya...

    I need some help with this form thingy...

    PHP Code:
    <?php

      $sql 
    "SELECT id, navn, parentid FROM grupper WHERE id > 0" ;
      
    $result mysql_query$sql ) or die (mysql_error()) ;

      
      echo 
    "<form action=visgruppemedroller.php method=get>";
      echo 
    "<input type=hidden name=gruppeid value=$rad[id]>";
      echo 
    "<select name=velggruppe>";
      while ( 
    $rad3 mysql_fetch_array$result ) ) {
        echo 
    "<option>$rad3[navn]</option>";

      }
      echo 
    "<input type=submit name=submit value=Vis></form>";
      
    $rad mysql_fetch_array$result );
      echo 
    "<p>$rad[navn]<br>";
      echo 
    "$rad[parentid]</p>";
    ?>
    When I choose a group from the select box "velggruppe" I want the info from that group to be echoed as you can see in the lower part of the code ($rad[navn] and $rad[parentid])

    As you can probably see, I haven't gotten it right yet... But I'm not sure what to change... Can you help?

  2. #2
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont quite understand...do you need to make the selection options appear in a certain order or do you mean:

    <option value="$somevalue">$rad3[navn]</option>

    If you are being unable to show which option was selected, that's most likely coz you missed the VALUE part of the code.

    edit: oh, i tihnk i understand it now.

    isnt it supposed to be $rad3 instead of $rad?

    I need some sleep.
    Last edited by astericks; Mar 18, 2003 at 01:33.

  3. #3
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm a bit confused about what you're trying to do?

    The query has already been run and finished by the time you get down to the end, so there's no results for it to return...

    PHP Code:
        <form action="visgruppemedroller.php" method="get">
            <input type="hidden" name="gruppeid" value="<?=$rad['id']?>">
            <select name="velggruppe">
            <?
                $sql 
    "SELECT id, navn, parentid FROM grupper WHERE id > 0";
                
    $result mysql_query($sql) or die (mysql_error());
                
                while (
    $rad3 mysql_fetch_array($result))
                {
                    echo 
    "<option>$rad3['navn']</option>";
                }
            
    ?>
        <input type="submit" name="submit" value="Vis">
        </form>
    Is how I would do clean up the first part anyway

    But, what exactly do you want displayed near the bottom?

    PHP Code:
      $rad mysql_fetch_array($result);
      echo 
    "<p>$rad['navn']<br>";
      echo 
    "$rad['parentid']</p>"
    will echo out the last result, which is nothing

    Where does the rad[] array come from? is that something you do earlier?

  4. #4
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    without knowing anytihng about the norwegian language, I'd say 'rad' means 'row'.

    Just like many people like to pull out results as $row['myVar']...in norway would be $rad['myVar']

    i could be wrong...I'm very drowsy.

  5. #5
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I figured it meant something like that I was just wondering where "rad" came from as apposed to "rad3"

  6. #6
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I want is this: (I'm horrible at explaining my needs, sorry...)

    When I choose an option from the selectbox and click the submit button... The information for that group (the option in the selectbox) will show...

    That is the $rad[] array, which was incorrect and I changed it to $rad3[]

    So, when I click submit... Echo navn and parentid from the table grupper of the group that has been selected in the selectbox...

  7. #7
    ********* Poet X Q mano's Avatar
    Join Date
    Oct 2002
    Location
    Still Thulcandra
    Posts
    997
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok,

    I've cleaned a little bit of my code, it now looks like this...

    PHP Code:
    <?php
      
    <form action=visgruppemedroller.php method=get>
      <
    input type=hidden name=gruppeid value=$rad[id]>
      <
    select name=velggruppe>
    <?
    php

      $sql 
    "SELECT id, navn, parentid FROM grupper WHERE id = $_GET[gruppeid];
      
    $result mysql_query$sql ) or die (mysql_error()) ;

      
      echo 
    "";
      while ( 
    $rad3 mysql_fetch_array$result ) ) {
        echo 
    "<option value=$rad3[id]>$rad3[navn]</option>";

        }

      
    ?>
      <input type=submit name=submit value=Vis></form>
      <?php
      
      $rad 
    mysql_fetch_array$result );
      echo 
    "<p>$rad[navn]<br>";
      echo 
    "$rad[parentid]</p>";
    ?>
    As you probably see, the $_GET[gruppeid] in the $sql is causing some havoc...

    How can I make it so it is defined as the rad3[id] when I click the submit-button... ?

    I think that is what the script needs...

  8. #8
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Aren't you selecting the gruppeid in your drop down list? Why do you have the hidden field with the gruppeid then?

    If I've understood this correct, I think this sql would work:
    $sql = "SELECT id, navn, parentid FROM grupper WHERE id = $_GET[velggruppe]";

    You need to set $_GET['velggruppe'] to an initial value if it's not set by the form.

    -Helge


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
  •