Passing array elements to function.
Posted: Sun Mar 07, 2010 4:54 pm
I created two arrays, $Tables and $Fields. I want to pass values from these arrays to a function selectDistinct() which produces a
dynamic select list.
Arrays as follows:
Array - $Tables
Array
(
[0] => account
)
=======================================
Array - $Fields
hr><pre>Array
(
[0] => IDno
[1] => VendorId
[2] => AccountNo
[3] => Company
[4] => Category
[5] => InternetEmailOther
[6] => Phone
[7] => InternetId
[8] => PW
[9] => LicenseKeyPin
[10] => EmailOfRecord
[11] => Hints
)
========================================
I'm calling selectDistinct() with $Tables[0], $Fields[4] as:
selectDistinct($connection, $Tables[0], $Fields[4], "Category", "All", $partname)
Function definition is:
function selectDistinct ($connection, $tableName, $fieldName, $selectedName, $defaultValue, $partname)
{
.
.
.
.
// Get the value for the field to be displayed
43. $result = $row[$fieldName];
.
.
}
=========================================================
this does not work! producing:
</pre><br>Category <br>account <br>Category<br><br><hr>
<select name="Category">Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>
<br>
=========================================================
if I replace $fieldName in 43. above with 'Category'
as : $row['Category'] it works producing :
</pre><br>Category <br>account <br>Category<br><br><hr>
<select name="Category">Value AllResult Bank
<option value="Bank">Bank</option>Value AllResult Computer
<option value="Computer">Computer</option>Value AllResult Gov
<option value="Gov">Gov</option>Value AllResult Linux
<option value="Linux">Linux</option>Value AllResult Map
<option value="Map">Map</option>Value AllResult News
<option value="News">News</option>Value AllResult Phone
<option value="Phone">Phone</option>Value AllResult Sales
<option value="Sales">Sales</option>Value AllResult Travel
<option value="Travel">Travel</option>Value AllResult Windows
<option value="Windows">Windows</option>
<br>
<input type="submit" value="Name" />
==================================================================
if I call selectDistinct() using "Category" in lieu of $Fields[4] it also works.
I'm pretty sure this is something stupid on my part but it is driving me nuts
Any help on why this won't work is greatly appreciated!!
Thanks in advance,
Rick_P
=============================================================
PS: This little test works.
function paramtest($array) {
print $array;
}
paramtest($Fields[4]);
produces: Category
dynamic select list.
Arrays as follows:
Array - $Tables
Array
(
[0] => account
)
=======================================
Array - $Fields
hr><pre>Array
(
[0] => IDno
[1] => VendorId
[2] => AccountNo
[3] => Company
[4] => Category
[5] => InternetEmailOther
[6] => Phone
[7] => InternetId
[8] => PW
[9] => LicenseKeyPin
[10] => EmailOfRecord
[11] => Hints
)
========================================
I'm calling selectDistinct() with $Tables[0], $Fields[4] as:
selectDistinct($connection, $Tables[0], $Fields[4], "Category", "All", $partname)
Function definition is:
function selectDistinct ($connection, $tableName, $fieldName, $selectedName, $defaultValue, $partname)
{
.
.
.
.
// Get the value for the field to be displayed
43. $result = $row[$fieldName];
.
.
}
=========================================================
this does not work! producing:
</pre><br>Category <br>account <br>Category<br><br><hr>
<select name="Category">Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>Value AllResult
<option value=""></option>
<br>
=========================================================
if I replace $fieldName in 43. above with 'Category'
as : $row['Category'] it works producing :
</pre><br>Category <br>account <br>Category<br><br><hr>
<select name="Category">Value AllResult Bank
<option value="Bank">Bank</option>Value AllResult Computer
<option value="Computer">Computer</option>Value AllResult Gov
<option value="Gov">Gov</option>Value AllResult Linux
<option value="Linux">Linux</option>Value AllResult Map
<option value="Map">Map</option>Value AllResult News
<option value="News">News</option>Value AllResult Phone
<option value="Phone">Phone</option>Value AllResult Sales
<option value="Sales">Sales</option>Value AllResult Travel
<option value="Travel">Travel</option>Value AllResult Windows
<option value="Windows">Windows</option>
<br>
<input type="submit" value="Name" />
==================================================================
if I call selectDistinct() using "Category" in lieu of $Fields[4] it also works.
I'm pretty sure this is something stupid on my part but it is driving me nuts
Any help on why this won't work is greatly appreciated!!
Thanks in advance,
Rick_P
=============================================================
PS: This little test works.
function paramtest($array) {
print $array;
}
paramtest($Fields[4]);
produces: Category