Jump to content

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.