Re: <select> not populating form fields (php,mysql)



Ian Rutgers wrote:
"David Haynes" <david.haynes2@xxxxxxxxxxxx> wrote in message news:MRz8f.9276$AF.1225@xxxxxxxxxxxxxxxxxxxxxxxx
Ian Rutgers wrote:
Situation:

I have a form which collects a bunch of data. The form accesses two tables (users and assignment_details). The user table is accessed to get the userid (to be saved in an assignment_details record) and to display other users table info (for display only). There is other information being collected to be saved in the assignment_details table, but it is not relevant to the issue.

I am using a <select> to display user names, and extract the appropriate userid. The <select> tag uses a query to pull all the names from the users table. When the form is loaded all defined fields from the users table are displayed on the form. Selecting a different name doesn't result in extracting and displaying the result of the user fields (as in the code below): ... help!
.
.
.
<td><select name="adetails_employee_id">
<?php
do {
?>
<option value="<?php echo $row_rsEmployeeLookup['id_usr']?>"><?php echo ($row_rsEmployeeLookup['first_name_usr'] . ' ' . $row_rsEmployeeLookup['last_name_usr']);?></option>
<?php
} while ($row_rsEmployeeLookup = mysql_fetch_assoc($rsEmployeeLookup));
$rows = mysql_num_rows($rsEmployeeLookup);
if($rows > 0) {
mysql_data_seek($rsEmployeeLookup, 0);
$row_rsEmployeeLookup = mysql_fetch_assoc($rsEmployeeLookup);
}
?>
</select>
</td>
</tr>
<tr>
<td>mobile phone</td>
<td><?php echo $row_rsEmployeeLookup['mobile_usr']; ?></td>
</tr>
etc.
I think you are missing a fundamental concept about server-side processing which is that once the server responds to the browser (i.e. PHP has processed its response) the page is essentially static.

Try doing a right-click view page source in your browser to see what PHP has sent to the browser and then ask yourself how was the new query based on the select going to happen.

In other words, since all queries need to be resolved on the server, how is the server going to know what you selected?

-david-

I see what you're saying. I assume then I have to do a separate query "on select" to look up and display the other fields?

Ian


Assuming that you don't want to use a client-side tool - like javascript - to do this, I would set this php page up so that it could handle two cases: 1. where adetails_employee_id was not set and 2. where adetails_employee_id was set. Then the form around the select would simply call this php page. Roughly (assuming a POST method form)...

<?php
if( isset($_POST['adetails_employee_id']) ) {
	// code to lookup an employee based on the adetails_employee_id
} else {
	// default without employee lookup
}
?>

....
<form method="POST" action="">
<select name="adetails_employee_id" onchange="Javascript:Submit()">
<option value="...">...</option>
</select>
</form>

I hope this helps.

-david-

.



Relevant Pages

  • Re: +" in dateiname.html = 404
    ... Wenn dann der Server den Browser nicht versteht, ... Php ist immer noch nicht wirklich threadsave. ... Apache im preforked mode laufen damit es mit php zu keinen ...
    (de.comp.os.os2.apps)
  • Re: Function execution before page reload
    ... browser. ... Interaction between PHP and the browser is one-way - the PHP ... > In the short example above does the script execute the function BEFORE ... The server receives information from the browser and sends html back to the ...
    (comp.lang.php)
  • Re: Function execution before page reload
    ... if ){printf("Can't connect to MySQL Server. ... browser. ... Interaction between PHP and the browser is one-way - the PHP ... loads the appropriate interpreter and calls it to execute the code. ...
    (comp.lang.php)
  • Re: Function execution before page reload
    ... if ){printf("Can't connect to MySQL Server. ... browser. ... Interaction between PHP and the browser is one-way - the PHP ... > In the short example above does the script execute the function BEFORE ...
    (comp.lang.php)
  • Re: Slide show: this should be fairly straightforward - a what language to use question
    ... Nothing appeared on my news server, ... and I sort of know what php does. ... > to a page where he sees the first slide and first caption associated ... If it's just a browser he needs, ...
    (comp.lang.php)