dynamically display corresponding values from database in a label

i have a combobox filled with menuitems from a restaurant. I need to be able to lookup the corresponding menuitem and display it’s corresponding price from the database in an adjacent label on the same form. Can this be done using php or do i need to used jquery. If so could someone please provide the code to do this as am new to php, jquery.

if the above is not possible is it possible to output the corresponding price value of the menuitem on another form. how can this be done.

once you have the menuitems selected and you just need to a run query saying give me the price of this items

SELECT `price` FROM `table_name` WHERE itemname='pizza'

[php]
SELECT price FROM table_name WHERE itemname=’$itemName’
[/php]

here is the code i have. how do i assign bind the result of the query to the label on the same form. below is my code.
[php]<? if (!$db)
{
echo “Error: Could not connect to database. Please try again later.”;
exit;
}
mysql_select_db(“orders”);
$query = “select itemName from menuitems “;
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
//$itemPrice = $row[“itemPrice”];
for($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
//echo htmlspecialchars( stripslashes($row[“tableNo”]));
//echo “<option value=”.$row[“itemName”].” >”.$row[“itemName”]."";
echo “”.$row[“itemName”]."";
//echo “

”;
}
if (!$db)
{
	echo "Error: Could not connect to database. Please try again later.";
	exit;		
}
mysql_select_db("orders");
$query = "select itemPrice from menuitems where itemPrice = '$itemName'";

$result = mysql_query($query);
$num_results = mysql_num_rows($result);
for($i=0; $i < $num_results; $i++)
{
	$row = mysql_fetch_array($result);
	//echo htmlspecialchars( stripslashes($row["tableNo"])); 
	//echo "<option value=".$row["itemPrice"]." >".$row["itemPrice"]."</option>";
	//echo "<option value=".$row["itemPrice"]." >".$row["itemName"]." - ".$row["itemPrice"]."</option>";
	
	//echo "</p>";
	//echo "<label for="itemPrice" value=".$row["itemPrice"].">".$row["itemPrice"]."</label>";
	//echo "<option for="itemPrice" value=".$row["itemPrice"].">".$row["itemPrice"]."</option>";
	//echo "<label for="itemPrice" id="itemPrice">".$row["itemPrice"]."</label>";
}		

	?>[/php]

or how can i get the value of itemPrice on the next form coz what i need to do is insert a record into the database with the item ordered

eg
itemNamr, itemQty, itemPrice, totalPrice

backup original file and try to use this one , i dont know i found urs too messy.

[php]

<? include("../connect_db.php"); $result = mysql_query("select itemName from menuitems") or die(mysql_query); echo " "; while($rows = mysql_fetch_assoc($result)) { echo "".$rows["itemName"].""; } echo " "; if (isset($_POST['submit'])) //button must bee clicked in order to excute the below code { $result = mysql_query("select itemPrice from menuitems where itemName ='".$_POST['itemName']."'") or die(mysql_query); $prows = mysql_fetch_assoc($result) or die(mysql_query);; echo "".$prows["itemPrice"].""; } ?>

[/php]

thanks wilson. it’s working fine now.

im glad that it worked. press the + karma button if i helped

i will recommend some books that i have and email to you if you wish

hi wilson, i’ve just sent a message to you to your inbox.

Sponsor our Newsletter | Privacy Policy | Terms of Service