Hi - pretty sure I'm missing something very simple here...
In my code, I'm running a query over an MSSQL table and pulling out catalogue sections:
e.g.
Section number: 101
Section Name: Banana Trees
Section number: 102
Section Name: Apple Trees
I've populated an array with this:
$data = array("101"=>"Banana Trees","102"=>"Apple Trees");
In my html, I have a form with a number of drop downs. The drop down lists contain the same data - from the array. So doing a while loop over the array I can populate the select list. However, if trying to do that multiple times, the first select box gets populated, but subsequent ones are empty. Its almost like once you have referenced or used an array once, you cannot re-use it.
Does any one have any ideas on where I'm going wrong ?
Code Snippet below:
$prwebc = " select distinct catnum,catsec from database.dbo.catalogues where cat='UKJF'";
$prwebcres = mssql_query($prwebc);
For($aa=0; $r=mssql_fetch_row($prwebcres); ++$aa)
{
$prwebclist[$r[0]] = $r[1];
}
asort($prwebclist);
Then, in my HTML form:
$query = " SELECT * FROM [DATABASE].[dbo].[CATALOGUE] where prcono='01' and PRODUCT in ('".$sql_list."') and cat='UKJF' ";
$queryres = mssql_query($query);
print("<table border=2>");
for($ax=0; $ar=mssql_fetch_row($queryres); ++$ax)
{
print("<tr>");
print("<td>$ar[0]</td>");
print("<td>$ar[1]</td>");
print("<td>$ar[3] $ar[4]</td>");
print("<td><select name=\"PRWEBC\">");
while(list($k,$v)=each($prwebclist[$ax]))
{
print("<option value=$k");
if($k==$ar[8])
{
print(" SELECTED ");
}
print(">$v");
}
print("</option></select></td>");
print("<td>$ar[9]</td><td>$ar[10]</td><td>$ar[11]</td><td>$ar[12]</td><td>$ar[13]</td><td>$ar[14]</td><td>$ar[15]</td><td>$ar[16]</td><td>$ar[17]</td></tr>");
}
print("</table>");
There are 26 rows in the output which should create 26 drop down lists containing data from the array.