| 
	
 | 
 Posted by kenoli on 05/29/06 07:06 
I am having trouble getting included source code to work. 
The idea here is to create a pulldown list using an option field in a 
form where the option items are generated from data selectd from a look 
up table.  A function selects the data and puts it into an array that 
is used to create the pulldown menu.  When the code is placed directly 
into the php file it works fine, but when it is placed in the file 
using an include, the form displays, but the pull down menu is not 
created from the array. 
 
>From what I have read, included code should execute exactly as if it is 
in the script itself.  This doesn't work in this case.  Can anyone tell 
me what I am missing here?  I am wondering if it may have something to 
do with scope issues, but I can't figure out what is going on. 
 
Here are the details.  I have only included the relevant part of the 
form.  It is part of a table that inputs other data as well. 
 
================================================================ 
 
At the beginning of the script, I have included a function from an 
included file.  Like this: 
 
include ("functions.php");     //Include functions definition file. 
 
================================================================ 
 
This is the relevant function in the included file: 
 
function get_phonenames() { 
 
$query = "SELECT * FROM tlu_phone_type ORDER BY phone_type ASC"; 
$result = @mysql_query ($query); 
$row = mysql_fetch_array; 
 
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { 
		global $phonenames; 
		$phonenames .= "<option>{$row['phone_type']}</option>\n"; 
		} 
		return $phonenames; 
} 
 
================================================================ 
 
The following code correctly utilizes the function from the 
functions.php file and the array it returns to create the pulldown menu 
when I put it in the script itself, like this: 
 
get_phonenames(); 
 
print <<<ADDFORM 
<form> 
Phone Type: <select name="phone_type_1"><option>Select 
One</option>$phonenames</select Phone 1: <input name="phone_1" 
type="text" size="12" maxlength="12" /> 
</form> 
ADDFORM; 
 
(It correctly creates a drop down menu using data from the lookup table 
tlu_phone_type generated by the get_phone_types function and held in 
the array $phonenames.) 
 
================================================================ 
 
When I add the same code using an include like this: 
 
include "add_records.tpl";  //The content of add_record.tpl is exactly 
the same as the code above (see below). 
 
It prints the html correctly, but does does not create the options from 
the $phonenames array. 
 
Something is keeping the the php code from working in the form. 
 
I have tried invoking the function before the include with no sucess, 
rather than placing it in the included file.  This doesn't work either. 
 
================================================================ 
 
Content of add_record.tpl: 
 
get_phonenames(); 
 
print <<<ADDFORM 
<form> 
Phone Type: <select name="phone_type_1"><option>Select 
One</option>$phonenames</select Phone 1: <input name="phone_1" 
type="text" size="12" maxlength="12" /> 
</form> 
ADDFORM; 
 
================================================================ 
 
I look forward to any help I can get understanding what is going on 
here. 
 
I suspect a scope issue here, but can't figure it out. 
 
Thanks, 
 
--Kenoli 
 
Kenoli Oleari 
Neighborhood Assemblies Network 
kenoli@igc.org 
510-601-8217 
http://www.horizonsofchange.com 
http://www.sfnan.org
 
  
Navigation:
[Reply to this message] 
 |