Jump to content

form input select from using db


jr8rdt

Recommended Posts

Hello

I need to do form input select. the easiest thing would be hardcoding the values. but this is headache to maintain/grow. the smarter and obvious  way is to get the select option values from a database? but I am not quite sure how to do that . In addition  I have multiple input select in 1 program (hardware, user, sofware, etc). other than using database what are my options? what about flat file or xml?

 

<tr><td>Hardware</td>

<td><select name="hw">

<option value="Dual-Core AMD Opteron Processor 8218">Dual-Core AMD Opteron Processor 8218</option>

<option value="Proliant DL380">Proliant DL380</option>

<option value="Proliant DL585">Proliant DL585</option>

</select></td></tr>

 

<tr><td>User</td>

<td><select name="user">";

<option value='John'>John</option>";

<option value='Patrick'>Patrick</option>";

<option value='Kevin'>Kevin</option>";

<option value='Jason'>Jason</option>";

<option value='Glen'>Glen</option>";

<option value='Joe'>Joe</option>";

<option value='Dan'>Dan</option>";

<option value='Dennis'>Dennis</opt

Link to comment
https://forums.phpfreaks.com/topic/55727-form-input-select-from-using-db/
Share on other sites

XML would be a decent way to go. But I think the database would be easier.

 

You would need a table with an id field, a name field (for the name of the select) and a value field which houses the data something like  id::value,id2::value2, so you can explode the data and easily parse it out for displaying in an option statement.

I have this snippet of code in my site for displaying a select box from the database

 

<select name="avatar_name">
<?php
	$sql11 = "select * from `avatar_blank` where `user_name` = '$username'";
   		$query11 = mysql_query($sql11) or die(mysql_error());
      				while($dd11 = mysql_fetch_array($query11)){
	$avatar_name = $dd11['avatar_name'];
echo "<option value=\"$avatar_name\">$avatar_name</option>";
			}
?>
</select>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.