I usually dont have a problem with simple CRUD work, but these queries in particular are boggling my mind. looking at it now, i may have an extra foreach... anyone have any ideas how i can properly execute this?
the code populates a form based on each distinct "dealer_id" (user) and populates a text field for every column in the table (dynamic amount of columns, based on new products, etc)... trouble is, it's iterating the last "dealer_id" (id 4) when populating the data in the fields...
for instance:
id comp1 dealer_id WTFwater vms water
---------------------------------------------------------------------------
3 7.00 vms 3.00 9.00
---------------------------------------------------------------------------
4 8.00 Boston 4.00 10.00
a (not so) working example can be found @
http://dealers.vmsalarms.com/portal/cart/admin/dealerPrice/populateDealer5.php
code (starting to become spaghetti):
$resultDealer = mysql_query("select distinct `dealer_id` from $dbname.dealerPrice order by `dealer_id` asc");
$dealerArray = array();
while ($rowSet = mysql_fetch_array($resultDealer)) {
array_push($dealerArray, $rowSet["dealer_id"]);
}
foreach ($dealerArray as $value1) {
$sql = "SHOW COLUMNS FROM $dbname.dealerPrice";
$result = mysql_query($sql);
echo "<span style=\"color:#0066ff\">" . $value1. "</span><br />";
echo "<form action=\"processPrice.php?action=add\" method=\"post\" enctype=\"multipart/form-data\" name=\"frmAddPrice\" id=\"frmAddPrice\">";
while ($row = mysql_fetch_row($result)) {
$equipArray = array();
$equipArray2 = array_push($equipArray, $row[0]);
foreach ($equipArray as $value) {
$resultPrice = mysql_query("select * from $dbname.dealerPrice");
$priceArray = array();
while ($rowSet1 = mysql_fetch_array($resultPrice)) {
array_push($priceArray, $rowSet1);
foreach ($priceArray as $price){
$equipPrice = $price[$value];
}
}
$equipId = "<div>" . $value . "<input value='". $equipPrice ."' name='" . $value . "' id='" . $value . "' /></div>";
}
echo $equipId;
}
echo "<input name=\"btnAddUser\" type=\"button\" id=\"btnAddUser\" value=\"Add Price\" class=\"box\" />
</form>";
}
any insight or direction will be HUGELY appreciated....