firekiller15
asked on
Why my array output is wrong
PHP
Why my array output is wrong
i have this code in code snippet
my result should be
supermarketname | Amount_of_candy | Amount_of_milo | AMount_of_milk |...
coles | 1.00000 | 5.00000 | 2.00000 |...
target | 5.00000 | 10.00000 | 3.00000 |...
...
but i get result as below
coles | "1.00000"|target| "5.00000"| parkson| "2.00000"... and so on
other words my amount become
coles | array[0] | target | array[1] | parkson | array[2] .. and so on
this is so wrong as you can see from my code GetAmount(()
coles should follow by array[0],array[1] and array[2]
but dont know why array[1] has go to target which is wrong
how to do this?
Why my array output is wrong
i have this code in code snippet
my result should be
supermarketname | Amount_of_candy | Amount_of_milo | AMount_of_milk |...
coles | 1.00000 | 5.00000 | 2.00000 |...
target | 5.00000 | 10.00000 | 3.00000 |...
...
but i get result as below
coles | "1.00000"|target| "5.00000"| parkson| "2.00000"... and so on
other words my amount become
coles | array[0] | target | array[1] | parkson | array[2] .. and so on
this is so wrong as you can see from my code GetAmount(()
coles should follow by array[0],array[1] and array[2]
but dont know why array[1] has go to target which is wrong
how to do this?
function GetAmount()
{
$ItemID = array(1234,6545,5468,9856,"no stock",4561,5466);
$arrayElement[3] = "no stock";
$supermarketID = 21;
$i = 0;
$j = 0;
for ($j = 0; $j < sizeof($ItemID); $j++)
{
if (($ItemID[$j] != $arrayElement[3])
{
$query = "SELECT getitem_std_amount( \"$supermarketID\", \"ItemID[$j]\") AS AMOUNT";
$result = mysql_query($query);
if(!$result) die("Query didn't work. " . mysql_error());
$temp = "";
while($row = mysql_fetch_array($result))
{
$temp = '"'.$row['AMOUNT'].'"';
}
$this->GetAmountReturn[$i++] .= $temp ;
}
}
else
{
$this->GetAmountReturn[$i] .= "\"Full Time Employees\" |";
$i++;
}
}
Wishing you a very happy birthday and a year full of things you love
function joinSUPERMARKETNAMEnAMOUNT()
{
//SUPERMARKETNAME select value is from another function
foreach(($this->GetSupermarketNameReturn_value as $i => $SupermarketName)
{
$data1 = "{$SupermarketName} | {$this->GetAmountReturn[$i]} ";
print_r( $data1);
}
}
}
ASKER
change it to $j doesnt make any different?
please post the modified code
ASKER
function GetAmount()
{
$ItemID = array(1234,6545,5468,9856, "no stock",4561,5466);
$arrayElement[3] = "no stock";
$supermarketID = 21;
for ($j = 0; $j < sizeof($ItemID); $j++)
{
if (($ItemID[$j] != $arrayElement[3])
{
$query = "SELECT getitem_std_amount( \"$supermarketID\", \"ItemID[$j]\") AS AMOUNT";
$result = mysql_query($query);
if(!$result) die("Query didn't work. " . mysql_error());
$temp = "";
while($row = mysql_fetch_array($result) )
{
$temp = '"'.$row['AMOUNT'].'"';
}
$this->GetAmountReturn[$j] .= $temp ;
}
}
else
{
$this->GetAmountReturn[$j] .= "\"Full Time Employees\" |";
}
}
Wishing you a very happy birthday and a year full of things you love
function joinSUPERMARKETNAMEnAMOUNT ()
{
//SUPERMARKETNAME select value is from another function
foreach(($this->GetSuperma rketNameRe turn_value as $i => $SupermarketName)
{
$data1 = "{$SupermarketName} | {$this->GetAmountReturn[$i ]} ";
print_r( $data1);
}
}
}
{
$ItemID = array(1234,6545,5468,9856,
$arrayElement[3] = "no stock";
$supermarketID = 21;
for ($j = 0; $j < sizeof($ItemID); $j++)
{
if (($ItemID[$j] != $arrayElement[3])
{
$query = "SELECT getitem_std_amount( \"$supermarketID\", \"ItemID[$j]\") AS AMOUNT";
$result = mysql_query($query);
if(!$result) die("Query didn't work. " . mysql_error());
$temp = "";
while($row = mysql_fetch_array($result)
{
$temp = '"'.$row['AMOUNT'].'"';
}
$this->GetAmountReturn[$j]
}
}
else
{
$this->GetAmountReturn[$j]
}
}
Wishing you a very happy birthday and a year full of things you love
function joinSUPERMARKETNAMEnAMOUNT
{
//SUPERMARKETNAME select value is from another function
foreach(($this->GetSuperma
{
$data1 = "{$SupermarketName} | {$this->GetAmountReturn[$i
print_r( $data1);
}
}
}
ok slowly I get the datastructure. The replace with $j is wrong, replace the $j in those two lines with $supermarketID
ASKER
is still the same
hm no clue and without knowing you datastructures it can get very complicated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$this->GetAmountReturn[$i+
}
}
else
{
$this->GetAmountReturn[$i]
$i++;
}
with
$this->GetAmountReturn[$j]
}
} else {
$this->GetAmountReturn[$j]
}