I'm new to php and I have been looking everywhere for info on how to take information from my sql table field and put it into a html form list.

Really depends what you're looking to do, but this is generally how it works. I would check out http://www.siteground.com/tutorials/php-mysql/display_table_data.htm

#Alter these variables as needed
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

#Change databasename
mysql_select_db("databasename", $conn);

#Change tablename
$query = "SELECT * FROM tablename";
$result = mysql_query($query);

#You now have that information stored in $result, where you go from here depends on what you are doing

I would like to take the results from one of the fields in my table "apparatus" and show those results in a form list.

It's a little hard to understand but I get the jist.

If put the information where you would put the value in html i.e. say you have a table data called username.

<input type="text" name="user_name" value="<?php echo $dbresults['username']; ?>" />


<textarea name="user_name"><?php echo $dbresults['username'] ?></textarea>

Hope this helps

Member Avatar

OK, I think I get you:

Let's assume your db table is something like this:

id (primary key)
apparatus (varchar)

Again I assume you want to place all the apparatus into a dropdown (select widget).

$items = "\n<select id=\"app_list\">";
$rs = mysql_query("SELECT * FROM apparatus ORDER BY apparatus");
while($data = mysql_fetch_array($rs)){
  $items .= "\n\t<option value=\"{$data['id']}\">" . stripslashes($data['apparatus']) . "</option>";
$items .="\n</select>";

Now the widget is stoed in the variable $items. So when you have the form, do this:

<form ...(form attributes)...>
  ...(other form widgets)...
  <?php echo $items;?>
  ...(other form widgets)...

The page which accepts the form data can now access the apparatus id thus:

$apparatus_id = $_POST['app_list'];