SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Drop Down Help

  1. #1
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drop Down Help

    Hello, I was wondering how to make a dropdown menue that is using a database. I am trying to use the following code but it gives me errors.
    PHP Code:
    $q mysql_query("SELECT * FROM plan");
    $r mysql_num_rows($q); 
    if (!
    $r) {
    echo 
    'There are no plans at this time';
    }
    echo 
    '<select name=</FONT>[size=1][color=#0000f0]"package"[/color][/size][size=1]>';
    while( 
    $r mysql_fetch_array($q) )
    {
    if (
    $package == .stripslashes($r['name']).) {
    echo (
    '<option selected value='.stripslashes($r['name']).'>'.stripslashes($r['name']).'</option>');
    } else {
    echo (
    '<option value='.stripslashes($r['name']).'>'.stripslashes($r['name']).'</option>');
    }

    echo 
    '</select>';

     [/
    size
    PHP Code:
    echo '<select name="package")';
    [
    size=1]if ($package == "name") {
    echo 
    '<option selected value=<font size="1"> 
     
    It is supposed to query a database and insert the name into the code like the following:
    </font>[size=1][color=#0000f0]"[color=#000000]name[/color]"[/color][/size][size=1]>name</option>'
    ;
    } else {
    echo 
    '<option value=[/size][size=1][color=#0000f0]"[color=#000000]name[/color]"[/color][/size][size=1]>name</option>';
    }[/
    size]
    [
    size=1]echo '</select>
    [/size] 
    I get the folowing errors with the first code.
    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

    Would you please post your suggestions here please. Thanks!


    [/size]
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Grand Rapids, MI
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WLHosting
    PHP Code:
    echo '<select name=</FONT>[size=1][color=#0000f0]"package"[/color][/size][size=1]>'
    I'm don't think thats standard HTML for the <select> tag, so I would change it to this:

    PHP Code:
    echo '<select name="package">'

  3. #3
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this instead:

    PHP Code:
    $qry = mysql_query("SELECT * FROM plan" );
    $num = mysql_num_rows($qry); 
    if ($num <= 0) {
    echo 'There are no plans at this time';
    }
    else {
    # begin to create your SELECT box from here
    ?>
    <select name='package' size='1'><?php
    # back to php again
    while($row mysql_fetch_array($qry) )
    {
    $Name stripslashes($row['name']);
    if(
    $Name == $package) {
    # btw, where does variable $package come from ?
    ?>
    <option selected value='<?php echo($Name); ?>'><?php echo($Name); ?></option>
    <?php
    }
    else {
    ?>
    <option value='<?php echo($Name); ?>'><?php echo($Name); ?></option>
    <?php
    }
    ?>
    </select>
    <?php
    .
    .
    # rest of your script

  4. #4
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will try that. Also the php function did add all of the font stuff in there. It messes up when I do it on my computer for some reason. Thanks for the help and I will check it out.
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers

  5. #5
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is weird. I have can creat a dropdown menue with the following code that just shows the value and the name of the option in a test file. But then when I put it into my script it gives me a T_STRING error.
    PHP Code:
    $q mysql_query("SELECT * FROM plan");
    $r mysql_num_rows($q);
    if (!
    $r) {
    echo 
    'There are no plans at this time';
    die;
    }
    echo 
    '<select name="package">';
    while( 
    $r mysql_fetch_array($q) )
    {
    echo (
    '<option value='.stripslashes($r['name']).'>'.stripslashes($r['name']).'</option>');

    echo 
    '</select>'
    I tried the code that was posted in previous replies and that does not work either. In Dr. Livingstons post about $package comming from. That is a previous drop down menue that is the same thing. This is in a form that I am working on. I hope that this helps some. Thanks!
    </FONT>
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers


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
  •