i am querying the DB as follows:
$result=mysql_query("SELECT name,items FROM mytable WHERE price='$price'");
now,i want to create an array to insert the values that are as a result of this query e'g let's say this is the resultant data:
name sellerid quantity
john 12 10
joel 23 20
brian 40 10
i.ve inserted this data into an array and want to manipulate it.(this is a trading platform),so let's say a user wanted to buy 25 items from the data in the array,and so to achieve this the script has to take the 10 items from john and 15 from joel(that adds up to 25) and then set their items to the remaining value i.e john's items=0 and joel's items=5.
this is the code.i am getting an error at this line about an undefined index
$assignedQuantityPerUser[ $row[ "sellerid" ] ] += $totalUnitsOrdered;
THIS IS THE REST OF THE CODE:
$query="SELECT itemquantity,sellerid FROM mytable WHERE price='$price'";
//it is a table containing data about people selling their commoditities and the program matches buyers and sellers by price
$foundItems = array();
// likely to be a parameter of a function...
$totalUnitsOrdered = 25;
// maps user to amount assigned from him
$assignedQuantityPerUser = array();
while ( $row = mysql_fetch_assoc( $cursor ) ) {
// Still order Quantity left?
if ( 0 < $totalUnitsOrdered ) {
if ( $row[ "itemquantity" ] <= $totalUnitsOrdered ) {
// assign all of $row[ "items" ]
$totalUnitsOrdered -= 0 + $row[ "itemquantity" ];
$assignedQuantityPerUser[ $row[ "sellerid" ] ] += 0 + $row[ "itemquantity" ];
**//this is where in getting an error:r[ $row[ "sellerid" ] is an undefined index**
} else {
// assign all the rest: $totalUnitsOrdered
$totalUnitsOrdered = 0;
$assignedQuantityPerUser[ $row[ "sellerid" ] ] += $totalUnitsOrdered;
}
}
$newItem[] = $row[ "sellerid" ];
$newItem[] = $row[ "itemquantity" ];
// Append $newItem to the end of $foundItems
$foundItems[] = $newItem;
} // while
kindly assist.thanks.