Jump to content

Small List/menu Problem


Jas0n

Recommended Posts

Hi Guys,

 

I'm using a listmenu to storage engineers names, however I'm trying to load the engineers name from the database so I can update the record.

 

	
        echo "Job Details<br>";
echo "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"updateAddJob\" id=\"formupdateJob\">"; 
echo "<select name=\"listEngineer\" id=\"listEngineer\">";
echo "<option value=\"Jason\" selected=\"selected\">Jason</option>";
echo "<option value=\"Paul\">Paul</option>";
echo "</select>";

 

For this particular job 'Paul' is the engineers name stored in the database.  How could I select his name instead etc...?

 

I hope you guys understand what I'm trying to do.

 

Thanks for the help,

Jas0n

Link to comment
https://forums.phpfreaks.com/topic/93675-small-listmenu-problem/
Share on other sites

<?php
$query="select * from enginers";
$result=mysql_qurey($query) or die("Error");

while($row=mysql_fetch_array($result))
{
?> 
<form action=\"\" method=\"post\" enctype=\"multipart/form-data\" name=\"updateAddJob\" id=\"formupdateJob\">"; 
<select n :(ame=\"listEngineer\" id=\"listEngineer\">
<option value=<?php echo $row["name"];?>"><?php echo $row["name"]?></option>
</select>
<?php
}
?>

might not be the correct version but it will work

[code]
$name=$_POST['listEngineer'];

$result=mysql_query("SELECT * FROM 'blah'(your table name) WHERE 'Name'(name of colomn where Engineet is named)=$name");

$row=mysql_fetch_assoc($result);

echo $row['Name'];(name of colomn to select information from)
echo $row['Age'];
echo $row['DOB'];
echo $row['Age'];

/*and so on*/

 

 

Then you can use update to update there name with a post get if you want here is an example of what i use.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Goshen Coach Part List</title>
<head>
<title>Edit Item</title>
</head>
<body>
<?php
ini_set('display_errors', '1');
error_reportIng(E_ALL);
include "databaseconnect.php";
$table="Item";
if (isset($_POST["Update"])) {
$ID=$_POST["ID"];
$Image=$_POST["Image"];
$Price=$_POST["Price"];
$Stock=$_POST["Stock"];
$Info=$_POST["Info"];
$Discription=$_POST["Discription"];
$idname= "ID";
$idvalue= $ID;
mysql_Query("UPDATE $table SET ID = '$ID' WHERE $idname = '$idvalue'", $link, "1");
mysql_Query("UPDATE $table SET Image = '$Image' WHERE $idname = '$idvalue'", $link, "1");
mysql_Query("UPDATE $table SET Price = '$Price' WHERE $idname = '$idvalue'", $link, "1");
mysql_Query("UPDATE $table SET Stock = '$Stock' WHERE $idname = '$idvalue'", $link, "1");
mysql_Query("UPDATE $table SET Info = '$Info' WHERE $idname = '$idvalue'", $link, "1");
mysql_Query("UPDATE $table SET Discription = '$Discription' WHERE $idname = '$idvalue'", $link, "1");
}
if (!isset($_POST["Load"])){
			echo "\nSelect item you wish to edit:";
			echo "\n<FORM action='".$_SERVER['PHP_SELF']."' method='post'>";
			echo "\n<SELECT name='ID'>";
			echo "\n<option label='' value=''>None</OPTION>";
				echo "\n<optgroup label='Item'>";
			echo "\n</OPTGROUP>";
			$tmp = array();
foreach (range('a','z') as $ltr) {
$tmp[] = '<optgroup label=\'' . strtoupper($ltr) . '\'>';
$result = mysql_query("SELECT * FROM $table WHERE `ID` LIKE '" . $ltr . "%' ORDER BY `ID`");
while ($row = mysql_fetch_assoc($result)) {
   $tmp[] = "<option value='$row[iD]'>$row[iD]</option>";
}
			$tmp[] = "\n</OPTGROUP>";
}
echo implode("\n",$tmp);
			echo "\n</SELECT>";
echo "\n<input type='SUBMIT' value='Load Item' Name='Load'>";
echo "</form>";
}

if (isset($_POST["Load"])) {
			echo "\n<FORM action='".$_SERVER['PHP_SELF']."' method='post'>";
$ID=$_POST["ID"];
$result = mysql_query("SELECT * FROM $table WHERE ID='$ID'");
$tmp = array();
while ($row = mysql_fetch_assoc($result)) {
$tmp[] = "Please type in the Name of the Item:<input type=\"text\" value=\"".$row['ID']."\" name=\"ID\" maxlength=\"30\" size=\"15\">";
$tmp[] = "Please type in the URL of the Item:<input type=\"text\" value=\"".$row['Image']."\" name=\"Image\" maxlength=\"30\" size=\"15\">";
$tmp[] = "Please type in the Price of the Item:<input type=\"text\" value=\"".$row['Price']."\" name=\"Price\" maxlength=\"30\" size=\"15\">";
$tmp[] = "Please type in the number of this Item in stock:<input type=\"text\" value=\"".$row['Stock']."\" name=\"Stock\" maxlength=\"30\" size=\"15\">";
$tmp[] = "Please type a discription of the Item that is to be used:<textarea name=\"Discription\" height=\"30\" width=\"60\">".$row['Discription']."</textarea>";
$tmp[] = "Please type a discription of how to Install the item: <textarea name=\"Info\" height=\"30\" width=\"60\">".$row['Info']."</textarea>";
}
echo implode("\n<br>",$tmp);
echo "\n<br><input type='SUBMIT' value='Update Item' Name='Update'>";
echo "</form>";
}
?>
</body>
</html>

 

If you have any questions about that fell free to ask my codes are confusing sometimes and not the cleanest[/code]

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.