andrewmoir
Fri 3rd Jun '05, 6:19am
Hello Guys/Girls,
I apologise for my poor PHP etiquette and layout skills (Uppercase, and lack of tabs before code)
I am attempting to populate a drop down list from my database.
I am populating the first array from a password table -it gets the customers and sites (from the username), then I do a search for all dates in the sample database which have that customer/site name. The dates are then posted to another array
1st - Get all the customers and sites
2nd - get dates from sample db where samples are in the Customer/site.
So its two arrays here - 1- while going through all the customer/sites, -2-select all dates from database that have those customer/sites
e.g.
------
<?php
$sqlcs="SELECT distinct customer,site FROM PERMISSIONSCUSTSITE WHERE USERNAME = '$usernam' order by customer, customer desc";
$resultcs=mysql_query($sqlcs);
while($rowcs=mysql_fetch_array($resultcs)){
$cust1=$rowcs["customer"];
$site1=$rowcs["site"];
echo "$cust1"; //just checking that all is ok
echo "$site1"; //just checking that all is ok
$sqlans="SELECT distinct registerdate FROM sample where customer='$cust1' and site='$site1' order by registerdate desc";
$result=mysql_query($sqlans);
}
?>
<FORM name="custform">
.......
<?php
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE=\"".$row['registerdate']."\">".$row['registerdate']."</OPTION>";
}
?>
.........
</FORM>
------
However only the dates from the last Customer/Site (in the customer/site array) are displayed in the form. So each time the "while($rowcs=mysql_fetch_array($resultcs))" is called it seems to reset the "$result=mysql_query($sqlans);" array instead of adding to it.
Why does it do this, I thought everytime you added to an array it simple appended the previous data to the current.
sorry if its confusing I tried my hardest to make it simple.
Thanks for the help.
Andrew
I apologise for my poor PHP etiquette and layout skills (Uppercase, and lack of tabs before code)
I am attempting to populate a drop down list from my database.
I am populating the first array from a password table -it gets the customers and sites (from the username), then I do a search for all dates in the sample database which have that customer/site name. The dates are then posted to another array
1st - Get all the customers and sites
2nd - get dates from sample db where samples are in the Customer/site.
So its two arrays here - 1- while going through all the customer/sites, -2-select all dates from database that have those customer/sites
e.g.
------
<?php
$sqlcs="SELECT distinct customer,site FROM PERMISSIONSCUSTSITE WHERE USERNAME = '$usernam' order by customer, customer desc";
$resultcs=mysql_query($sqlcs);
while($rowcs=mysql_fetch_array($resultcs)){
$cust1=$rowcs["customer"];
$site1=$rowcs["site"];
echo "$cust1"; //just checking that all is ok
echo "$site1"; //just checking that all is ok
$sqlans="SELECT distinct registerdate FROM sample where customer='$cust1' and site='$site1' order by registerdate desc";
$result=mysql_query($sqlans);
}
?>
<FORM name="custform">
.......
<?php
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE=\"".$row['registerdate']."\">".$row['registerdate']."</OPTION>";
}
?>
.........
</FORM>
------
However only the dates from the last Customer/Site (in the customer/site array) are displayed in the form. So each time the "while($rowcs=mysql_fetch_array($resultcs))" is called it seems to reset the "$result=mysql_query($sqlans);" array instead of adding to it.
Why does it do this, I thought everytime you added to an array it simple appended the previous data to the current.
sorry if its confusing I tried my hardest to make it simple.
Thanks for the help.
Andrew