is it possible to put a ------ line in a drop down list populated by an SQL database.

Discussion in 'PHP' started by Matt Ridge, Dec 22, 2011.

  1. #1
     <?php
    	 
    require_once('connectvars.php');
    	 
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); 
          $mysqli->select_db('comp');
    
    
          $result = $mysqli->query("SELECT * FROM comp"); 
    
    
          echo "<SELECT name='name'>\n";
          while($row = $result->fetch_assoc()) {
             echo "<option value='{$row['user_id']}'>{$row['name']}</option>\n";   
          }
          echo "</select>\n";
    
    
          $result->close(); 
    
    
          ?>
    
    Code (markup):

    I want to put a '-----' line between item 3 and 4 in a list.

    The database shows as thus:

    The items have an auto-increment in then the company.

    Here is the pull down menu.

    http://kaboomlabs.com/PDI/test2.php

    Is this possible?
     
    Matt Ridge, Dec 22, 2011 IP
  2. proactiv3

    proactiv3 Peon

    Messages:
    55
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    0
    #2
    <?php
    	 
    require_once('connectvars.php');
    	 
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); ]$mysqli->select_db('comp');
    $result = $mysqli->query("SELECT * FROM comp"); 
    $i = 0;
    
    echo "<SELECT name='name'>\n";
    
    while($row = $result->fetch_assoc()) {
     if ($i == 3) echo '<option value="lines">-----</option>';
     
     echo "<option value='{$row['user_id']}'>{$row['name']}</option>\n";
     
     $i++;
    }
    
    echo "</select>\n";
    $result->close();
    PHP:
     
    proactiv3, Dec 23, 2011 IP
  3. Matt Ridge

    Matt Ridge Peon

    Messages:
    166
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Will this ignore what is in line 3 or put a space after line 3? I'm just curious, this is the first time I've ever used scripting like this.
     
    Matt Ridge, Dec 27, 2011 IP
  4. proactiv3

    proactiv3 Peon

    Messages:
    55
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    0
    #4
    This will output something like this:

    <select name="name">
      <option value="1">user1</option>
      <option value="2">user2</option>
      <option value="3">user3</option>
      <option value="0">------</option>
      <option> value="4">user4</option>
      (...)
    </select>
    PHP:
    It will not skip any record.
     
    proactiv3, Dec 27, 2011 IP