Results 1 to 9 of 9

Thread: Drop Down Results

  1. #1

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

    Drop Down Results

    I have a sql qyery which i want to add the results to a drop down menu.

    PHP Code:
    <?php
    $link 
    mysql_connect (localhostuserpass);
    mysql_select_db (db12816e);
    $result mysql_query ("SELECT name From table");
    while (
    $row mysql_fetch_array($result));
    {
    ?>
    <select NAME="venue" size="1">
    <option value="something i guess">results</option>


    how do i get the results in the drop down menu???
    Last edited by kiwis; Apr 18th, 2004 at 09:49 PM.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    try this:
    PHP Code:
    <select name="select">
    <?
      $qry = mysql_query("SELECT name FROM table"); 
      while($arr = mysql_fetch_array($qry)){
        echo "  <option value='$arr[name']>$arr[name]\n";
      }
    ?>
    </select>
    Like Archer? Check out some Sterling Archer quotes.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139
    Originally posted by kows
    try this:
    PHP Code:
    <select name="select">
    <?
      $qry = mysql_query("SELECT name FROM table"); 
      while($arr = mysql_fetch_array($qry)){
        echo "  <option value='$arr[name']>$arr[name]\n";
      }
    ?>
    </select>
    I get this error

    Parse error: parse error, expecting `']'' in /home/httpd/vhosts/site.com/httpdocs/history.php on line 86

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I used this the other day....worked fine for me:


    PHP Code:
    $resultat1 mysql_query("SELECT sNavn FROM Sted",$db);

                                while(
    $arr1 mysql_fetch_array($resultat1)){
                                    
    $sNavn stripslashes($arr1["sNavn"]);
                                        echo 
    "  <option value=\"$arr1[sNavn]\">$arr1[sNavn]\n";
                                  } 

  5. #5
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    typing stuff up on the fly makes for syntax errors, you should've been able to fix it yourself.
    PHP Code:
    <select name="select"> 
    <? 
      $qry = mysql_query("SELECT name FROM table");  
      while($arr = mysql_fetch_array($qry)){ 
        echo "  <option value='$arr[name]'>$arr[name]\n"; 
      } 
    ?> 
    </select>
    Like Archer? Check out some Sterling Archer quotes.

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    I had to look twice to see that one.......well I guess both ways work...

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139
    sweet got it working... problem is the form is
    <form method="POST" action="gallery.php">

    PHP Code:
    <select size="1" name="cats" style="border-style: solid; border-width: 1">


      <option selected>-- Please select a category --</option>
    <?php
    while ($row mysql_fetch_array($result)) {
    ?>
      <option value="<?php echo $row["cat_id"];?>"><font face="Verdana" size="1"><?php echo $row["cat_name"];?></option>
    <?php
    }
    ?>
      </select>

    and the gallery.php script

    PHP Code:
    $result mysql_query ("SELECT * From gallery_cats where cat_id = $cat_id"); 

    this is not a vaild search option... how do i fix this??

  8. #8
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by kiwis
    sweet got it working... problem is the form is
    <form method="POST" action="gallery.php">

    PHP Code:
    <select size="1" name="cats" style="border-style: solid; border-width: 1">


      <option selected>-- Please select a category --</option>
    <?php
    while ($row mysql_fetch_array($result)) {
    ?>
      <option value="<?php echo $row["cat_id"];?>"><font face="Verdana" size="1"><?php echo $row["cat_name"];?></option>
    <?php
    }
    ?>
      </select>

    and the gallery.php script

    PHP Code:
    $result mysql_query ("SELECT * From gallery_cats where cat_id = $cat_id"); 

    this is not a vaild search option... how do i fix this??


    If gallery_cats are the table and cat_id is an atribute, then try this:

    PHP Code:
    $result mysql_query ("SELECT * From gallery_cats where cat_id = ".$cat_id.""); 

  9. #9
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    I suggest always putting your database search values within single quotes.
    PHP Code:
    $result mysql_query("SELECT * FROM gallery_cats WHERE cat_id='$cat_id'"); 
    And, also, try using <?=$var;?> to echo your variables instead of <?php echo $var;?>. It just makes it look nice/saves time.
    Like Archer? Check out some Sterling Archer quotes.

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