Dear Sirs
I have an data set as follows
while($row = oci_fetch_array($stid05, OCI_BOTH)) {
echo 'country '. $row[0];
echo 'visits'.$visits[1];
}
I need to create following array dunamiccaly
$series = array( array( country => "TAVGA",
visits => 256,
),
array( country => "hawar",
visits => 257,
),
array( country => "awesar",
visits => 258,
),
array( country => "zhinar",
visits => 259,
),
array( country => "BBB",
visits => 259,
),
);
Kindly assist me, how to generate
Thsnks
Gayan
Create PHP array with dynamic data
Moderator: General Moderators
-
gpdissanayake
- Forum Newbie
- Posts: 3
- Joined: Wed May 30, 2012 6:32 am
Re: Create PHP array with dynamic data
Try this code in while loop
$new_array[] = array("country" => COUNTRY_DB_FIELD, "visits" => VISIT_DB_FIELD);
$new_array[] = array("country" => COUNTRY_DB_FIELD, "visits" => VISIT_DB_FIELD);
-
gpdissanayake
- Forum Newbie
- Posts: 3
- Joined: Wed May 30, 2012 6:32 am
Re: Create PHP array with dynamic data
Hellow PBS
I tried. I am getting following array
Array ( [0] => Array ( [country] => AAA [visits] => 1 ) [1] => Array ( [country] => BBB [visits] => 2 ) [2] => Array ( [country] => CCC [visits] => 3 ) )
any idea to get the same as following array
$series = array( array( country => "TAVGA",
visits => 256,
),
array( country => "hawar",
visits => 257,
),
array( country => "awesar",
visits => 258,
),
array( country => "zhinar",
visits => 259,
),
array( country => "BBB",
visits => 259,
),
);
Please help
I tried. I am getting following array
Array ( [0] => Array ( [country] => AAA [visits] => 1 ) [1] => Array ( [country] => BBB [visits] => 2 ) [2] => Array ( [country] => CCC [visits] => 3 ) )
any idea to get the same as following array
$series = array( array( country => "TAVGA",
visits => 256,
),
array( country => "hawar",
visits => 257,
),
array( country => "awesar",
visits => 258,
),
array( country => "zhinar",
visits => 259,
),
array( country => "BBB",
visits => 259,
),
);
Please help
Re: Create PHP array with dynamic data
Did you try something like this?
That should do it. When you were echoing $row[0] and $row[1] were you getting the correct values?
Code: Select all
$series = Array();
while($row = oci_fetch_array($stid05, OCI_BOTH)) {
// Assuming that $row[0] is indeed country and $row[1] is indeed the visit count
$series[] = Array("country"=>$row[0], "visits"=>$row[1]);
}
Last edited by TylerH4 on Thu May 31, 2012 7:39 pm, edited 1 time in total.
-
gpdissanayake
- Forum Newbie
- Posts: 3
- Joined: Wed May 30, 2012 6:32 am
Re: Create PHP array with dynamic data
Yes Sir, I tried but I am getting something like below
Array ( [0] => Array ( [country] => AAA [visits] => 1 ) [1] => Array ( [country] => BBB [visits] => 2 ) [2] => Array ( [country] => CCC [visits] => 3 ) )
--------------------------------------
when I hard coaded country / visit array, then I am getting results perfecly (kindly refer below)
$series = array( array( country => "TAVGA",
visits => 256,
),
array( country => "hawar",
visits => 257,
),
);
But through my code i need to craete same array , (same patten) as above
kindly find code as below
$query05 = "select country,visits from country WHERE ROWNUM < 4";
$stid05 = oci_parse($conn, $query05);
$r05 = oci_execute($stid05);
while($row = oci_fetch_array($stid05, OCI_BOTH)) {
// code here
}
Please fill, inside the loop to generate my array
Thank a lot
Gayan
Array ( [0] => Array ( [country] => AAA [visits] => 1 ) [1] => Array ( [country] => BBB [visits] => 2 ) [2] => Array ( [country] => CCC [visits] => 3 ) )
--------------------------------------
when I hard coaded country / visit array, then I am getting results perfecly (kindly refer below)
$series = array( array( country => "TAVGA",
visits => 256,
),
array( country => "hawar",
visits => 257,
),
);
But through my code i need to craete same array , (same patten) as above
kindly find code as below
$query05 = "select country,visits from country WHERE ROWNUM < 4";
$stid05 = oci_parse($conn, $query05);
$r05 = oci_execute($stid05);
while($row = oci_fetch_array($stid05, OCI_BOTH)) {
// code here
}
Please fill, inside the loop to generate my array
Thank a lot
Gayan
Re: Create PHP array with dynamic data
Are you sure there are no errors in your query and the query is returning data? Also, can you run the following code and post the exact output?
Code: Select all
$query05 = "select country,visits from country WHERE ROWNUM < 4";
$stid05 = oci_parse($conn, $query05);
$r05 = oci_execute($stid05);
while($row = oci_fetch_array($stid05, OCI_BOTH)) {
var_dump($row);
}