firekiller15
asked on
How to combine data of 3 or more elements in array and print it in one row
PHP
How to combine data of 5 elements in array and print it in one row
I have this code in my code snippet
in my code i get this output
ouput
coles | "1.00000"|coles| "5.00000"| coles| "2.00000"... and so on
from above clearly state that one "coles" repeat itself to print out different value of AMOUNT.
how to make it to print out as follow
coles | "1.00000"| "5.00000"|"2.00000"... and so on
that no coles is repeated and amount is printed in the same row
How to combine data of 5 elements in array and print it in one row
I have this code in my code snippet
in my code i get this output
ouput
coles | "1.00000"|coles| "5.00000"| coles| "2.00000"... and so on
from above clearly state that one "coles" repeat itself to print out different value of AMOUNT.
how to make it to print out as follow
coles | "1.00000"| "5.00000"|"2.00000"... and so on
that no coles is repeated and amount is printed in the same row
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());
while($row = mysql_fetch_array($result))
{
$this->GetAmountReturn[$i] .= '"'.$row['AMOUNT'].'"';
$i++;
}
}
else
{
$this->GetAmountReturn[$i] .= "\"Full Time Employees\" |";
$i++;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
why the output become empty?
Array ( [0] => "" ) Array ( [0] => "" [1] => "" ) Array ( [0] => "" [1] => "" [2] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" [4] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" [4] => "" [5] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" [4] => "" [5] => "" [6] => "" ) Array
Array ( [0] => "" ) Array ( [0] => "" [1] => "" ) Array ( [0] => "" [1] => "" [2] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" [4] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" [4] => "" [5] => "" ) Array ( [0] => "" [1] => "" [2] => "" [3] => "" [4] => "" [5] => "" [6] => "" ) Array
ASKER
you code looks weird as
$temp="";
while($row = mysql_fetch_array($result) )
{
$temp .= '"'.$row['AMOUNT'].'"';
$i++;
}
$this->GetAmountReturn[$i] .= $temp;
}
$this->GetAmountReturn is outside the loop . can it get the data from mysql_fetch_array?
$temp="";
while($row = mysql_fetch_array($result)
{
$temp .= '"'.$row['AMOUNT'].'"';
$i++;
}
$this->GetAmountReturn[$i]
}
$this->GetAmountReturn is outside the loop . can it get the data from mysql_fetch_array?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what is the difference btw them?
ASKER
the output result of my code your yours seems like thesame
what is the purpose of your code?
why need to set a variable $temp to empty string?
what is the purpose of your code?
why need to set a variable $temp to empty string?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Fire killer15,
This question seems to duplicate your other question
https://www.experts-exchange.com/questions/23481937/Why-my-array-output-is-wrong.html
You would probably get better input from experts if not asking them in parallel.
And if they are duplicate, how are you going to allocate points to both questions?
This question seems to duplicate your other question
https://www.experts-exchange.com/questions/23481937/Why-my-array-output-is-wrong.html
You would probably get better input from experts if not asking them in parallel.
And if they are duplicate, how are you going to allocate points to both questions?
ASKER
$i++;
do i still need $i++?