<?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?
<?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:
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.
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.