PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a form which I use to populate a mysql DB with values entered into the form, I am
converting some fields into dropdown menus which are populated through a query on the DB
and the user selects the desired data.
My original HTML code for the field "Salesman" in the DB
I give you some background there are two tables one with "Salesmen" and one is the "projects" they are working on.
So the "Add" gathers information from the form and the selection from the "Salesmen" table dropdown box. This information
is posted into the "Projects" table.
However when the update portion of the code the "Salesman" is picked from the "Projects" table and not the "Salesmen" Table.
I need it to display the correct Salesmen & allow me to select from the "Salesmen" table if I need to select a different value.
I display a form with a dropdown box with values pulled from TABLE1, the user selects the desired option
& click "Submit" the value is posted into TABLE2
The user then decides to update there selection, so he clicks the update form.
Here's the problem
How can I get the update form to display the value the user posted into TABLE2 but offer him the selection values from TABLE1 again so he can change the selection & post it again into TABLE1
JimiH, can you possible edit your posts so that you don't continually reply to your posting? It gives the apearance of bumping, which is heavily frowned upon here.
As for your question, can you clarify it a little bit? You say you have a result set that populate the select list. You post the form containing the select list and you want to capture that value? Is that right?
The problem is I can post a value selected from a dropdown linked to mysql table1 into another mysql Table2. but I cant display the posted value from Table2 into my update form dropdown box along with the other options from Table1, so the user can change it if required.
Ok, I am not trying to dumb this down, I swear. I just want to be able to understand what you are doing. Your first page runs a query that pulls all salesmen and populates a select list. Something like this...
<?php
// Grab the people to make the list from
$sql = "SELECT person_id, person_name FROM people";
if (!$result = mysql_query($sql))
{
die('Cannot get the person list: ' . mysql_error());
}
// Build a list now
echo '<select name="person">';
while ($row = mysql_fetch_array($result))
{
echo '<option value="' . $row['person_id'] . '">' . $row['person_name'] . '</option>';
}
echo '</select>';
?>
Your post page then would have something like this to get the value...
<?php
$person = 0;
if (isset($_POST['person_id']))
{
$person = $_POST['person_id'];
}
if ($person != 0)
{
// we have a passed value, lets do something
}
?>
What is it that you want to do on this page in addition to grabbing the passed form value?
There are two ways to do that... one, grab the information from the 'projects' table as it relates to that one row, and append that into the select list created by the information in 'people' (so essentially two different record sets put together in one output), or... 2) if the information that is in 'projects' already matches what is in 'people', then mark it as 'selected="selected"' by doing an if check while looping the result set from the 'projects' information.