Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mulitple queries on one page.

Status
Not open for further replies.

pugs421

Technical User
Nov 25, 2002
114
US
I have a database table called packages which contains the various camera packages that we receive. I want to use this table to populate a drop down menu. When the package is selected and submitted, I would like the values in the form fields on the page to be populated with the values from the packages table (camera Model, camera bag model, Microphone model,etc.) I am fairly new to php, and I seem to be having some trouble with two queries on the same page.


<?php

require_once('Connections/info.php');

$sql = "SELECT * FROM packages";
$result = mysql_query($sql) or die(mysql_error());
$num_results = mysql_num_rows($result);


if (isset($_POST['Submit1']))
{
$uniqueID = $_POST['uniqueID'];
$sql = "SELECT * FROM packages WHERE uniqueID = $uniqueID";
$result2 = mysql_query($sql) or die(mysql_error());
}

?>
<html>
<head>
<title>Inventory</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>


<?php
echo "<form name=\"dropdown\" method=\"post\" action=".$_SERVER['PHP_SELF']."><select name=\"uniqueID\">";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<option value=".$row['uniqueID'].">".$row['packageName']."</option>";
}
echo "</select>";
echo "<input type='hidden' name='dropdown' value='submit'>";
echo "<input type=\"submit\" name=\"Submit1\" value=\"Submit\"></form>";
?>

<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']?>">
<table width="300" border="1" cellspacing="0" cellpadding="0">
<tr>
<td>Camera Model</td>
<td><input name="cameraModel" type="text" id="cameraModel" value="<?php echo $_POST['cameraModel']?>" size="20" maxlength="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>


If someone could give me some insight on how something like this would work I would really appreciate it.

Thanks
 
I dont really understand your question. The Value you are giving to your drop down menu for the first form is uniqueID for the second form is cameraModel. You have two submits submit1 and submit.

Are you trying to display these values or update..or even submit them somewhere?

 
I would like to populate the text fields with the values from returned from the query
$sql = "SELECT * FROM packages WHERE uniqueID = $uniqueID";

The query will be executed if (isset($_POST['Submit1'])). The the page will return the values from the query into the text fields. After I accomplish that, the submit button at the bottom of the page will submit the values to be update the database table ( value="<?php echo $_POST['cameraModel']?>"). Camera model for example is a field which value should be retrieved from the query:

"SELECT * FROM packages WHERE uniqueID = $uniqueID";

Thanks, for the help.

I hope I made myself more clear.

 
pugs421:
The problem is your methodology.

PHP scripts, like all web apps, do not run continuously. A script runs and produces HTML then quits. The browser renders the HTML and the user manipulates the page and submits. The script to which the page is submitted runs, processes the input, produces output, then quits. The browser renders this new HTML, etc., etc., etc.

If the content of one SELECT is dependent on the value the user chooses for another, the form must be submitted before PHP can populate the second SELECT.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top