Getting only the last array data when i looped all arrays - php

I'm trying to use Facebook Graph API to get comments from the last 2 posts from my accounts
I wrote the code and it works but it only returns the second post (the last array) only
this my code :
$postItems = $postsArray['posts']['data'];
foreach ($postItems as $post) {
$fullPostId = $post['id'];
$comments_number = 10;
$facebook_graph_api2 = "https://graph.facebook.com/v2.4/$fullPostId/comments?access_token=$accToken&pretty=1&summary=true&limit=$comments_number&after";
$jsonData = grab_page($facebook_graph_api2,$accCookie);
$postDataArrays = json_decode($jsonData, true);
$CommentsItems = $postDataArrays['data'];
}
//foreach($CommentItems as $item) {
// echo $users = $item['from']['id'].'\n';
//}
// #$postItems = $postsArray['data'];
/** Update Balance Code **/
$toolId = '87637';
#$itemsCount = #count($CommentItems);
$toolPrice = toolPrice($toolId)*$itemsCount;
$finalBalance = updateBalance($toolPrice);
/** Update Balance Code **/
if ($finalBalance) {
if (isset($CommentItems)) {
echo '{"status":1,"balance":'.$finalBalance.',"message":"Success !","data":"';
foreach($CommentItems as $item) {
echo $users = $item['from']['id'].'\n';
// echo json_encode($users, JSON_FORCE_OBJECT);
// $items[] = $item['from']['id'];
}
// print_r($items);
// echo '{"status":1,"message":"Success !","data":"'.$items.'"}';
echo '"}';
}elseif( isset($postDataArray['error']) && $postDataArray['error']['code']== 1 ){
$msgError = $postDataArray['error']['message'];
echo '{"status":0,"message":"Error !","reason":"'.$msgError.'"}';
}else{
echo '{"status":0,"message":"Error !","reason":"Please Update Your Facebook Access Token"}';
}
}else{
echo '{"status":0,"message":"Error !","reason":"You do not have enough funds on balance"}';
}
The code above returns only last array data not all posts data.
this is an example of $postDataArrays data should be
Array
(
[data] => Array (
[0] => Array
(
[created_time] => 2023-02-08T14:46:12+0000
[from] => Array
(
[name] => Name1
[id] => id1
)
[message] => test Message
[id] => 61xxxxxxxxxxx_12xxxxxxxxxxxx
)
[1] => Array
(
[created_time] => 2023-02-08T14:42:52+0000
[from] => Array
(
[name] => name2
[id] => id2
)
[message] => test Message
[id] => 61xxxxxxxxxx_7xxxxxxxxxxxx
)
)
[paging] => Array
(
[next] => https://graph.facebook.com/v2.4/92xxxxxxxxxxxx_61xxxxxxxxxxxxxxxxxx/comments?access_token=EAAG&pretty=1&summary=true&limit=2&after
)
[summary] => Array
(
[order] => ranked
[total_count] => 58
[can_comment] => 1
)
)
Array
(
[data] => Array
(
[0] => Array
(
[created_time] => 2023-02-07T18:23:40+0000
[from] => Array
(
[name] => name1 from array 2
[id] => id2 from array 2
)
[message] => test Message
[id] => 6xxxxxxxxxxxxxx_xxxxxxxxxxxxxxxx
)
[1] => Array
(
[created_time] => 2023-02-07T18:20:49+0000
[from] => Array
(
[name] => name2 from array 2
[id] => id2 from array 2
)
[message] => test Message
[id] => 6xxxxxxxxxxxxxx_xxxxxxxxxx
)
)
[paging] => Array
(
[next] => https://graph.facebook.com/v2.4/9xxxxxxxxxxxxxxxxxxxxx/comments?access_token=EAAG&pretty=1&summary=true&limit=2&after
)
[summary] => Array
(
[order] => ranked
[total_count] => 121
[can_comment] => 1
)
)
the arrays above should return 4 users but it returns only last 2 users

First i create an array
$responses= array();
And modified the code and put all neded data inside the array
foreach ($postItems as $post) {
$fullPostId = $post['id'];
$comments_number = 3000;
$facebook_graph_api2 = "https://graph.facebook.com/v2.4/$fullPostId/comments?access_token=$accToken&pretty=1&summary=true&limit=$comments_number&after";
$jsonData = grab_page($facebook_graph_api2,$accCookie);
$postDataArray = json_decode($jsonData, true);
$CommentsItems = $postDataArray['data'];
foreach($CommentsItems as $item) {
$users = $item['from']['id'];
$userId['user_id'] = $users;
$responses[] = $userId['user_id'];
}
}
Then , Encoded the the final response to be json , and i decoded it again
$enResponse = json_encode($responses);
$allComments = json_decode($enResponse,true);
To show all data , just loop $allComments
foreach($allComments as $item) {
echo $users = $item.'\n';
}

Related

Compare different arrays structures

I have two arrays with different structures. Array 1 and Array 2 that I will name from MyList and MyFiles. I would get to return only MyList values that do not have in MyFiles. But the two arrays have different structures and I'm having trouble trying to compare
MyList
Array
(
[info] => Array
(
[0] => Array
(
[player] => Messi
[week] => Array
(
[id] => 252
[videos] => Array
(
[0] => Array
(
[id] => 2929850
[link] => goals.mp4
)
[1] => Array
(
[id] => 2929848
[link] => best.mp4
)
[2] => Array
(
[id] => 2929847
[link] => dribbling.mp4
)
)
)
)
[1] => Array
(
[player] => CR7
[week] => Array
(
[id] => 251
[videos] => Array
(
[0] => Array
(
[id] => 2929796
[link] => goals.mp4
)
[1] => Array
(
[id] => 2929795
[link] => best.mp4
)
)
)
)
[2] => Array
(
[player] => Neymar
[week] => Array
(
[id] => 253
[videos] => Array
(
[0] => Array
(
[id] => 2929794
[link] => goals.mp4
)
[1] => Array
(
[id] => 2929793
[link] => best.mp4
)
)
)
)
)
)
MyFiles Array
Array
(
[252] => Array
(
[0] => Array
(
[id] => 2929850
[link] => goals.mp4
)
[1] => Array
(
[id] => 2929848
[link] => best.mp4
)
)
[251] => Array
(
[0] => Array
(
[id] => 2929796
[link] => goals.mp4
)
[1] => Array
(
[id] => 2929795
[link] => best.mp4
)
)
)
the comparison must be made by id of the week and id of the video
I tried this but it did not work out:
$new = array();
foreach ($list['info'] as $source) {
foreach ($source["week"]['videos'] as $keys => $videos) {
foreach ($file as $key => $upload) {
if ($source["week"]["id"] == $key ) {
for($i=0; $i<count($source["week"]["videos"]); $i++){
if($videos["id"] == $upload[$i]["id"]){
unset($videos);
}else{
$new[] = $videos;
}
}
} else {
$new[] = $videos;
}
}
}
}
The expected return would be something like this.
Array
(
[info] => Array
(
[0] => Array
(
[player] => Messi
[week] => Array
(
[id] => 252
[videos] => Array
(
[2] => Array
(
[id] => 2929847
[link] => dribbling.mp4
)
)
)
)
[2] => Array
(
[player] => Neymar
[week] => Array
(
[id] => 253
[videos] => Array
(
[0] => Array
(
[id] => 2929794
[link] => goals.mp4
)
[1] => Array
(
[id] => 2929793
[link] => best.mp4
)
)
)
)
)
)
I have hidden the array in a usable format for my sake in the future should this answer be incorrect and need changing.
$desired = array();
$desired['info'][0]['player'] = 'Messi';
$desired['info'][0]['week']['id'] = 252;
$desired['info'][0]['week']['videos'][2]['id'] = 2929847;
$desired['info'][0]['week']['videos'][2]['link'] = 'dribbling.mp4';
$desired['info'][2]['player'] = 'Neymar';
$desired['info'][2]['week']['id'] = 253;
$desired['info'][2]['week']['videos'][0]['id'] = 2929794;
$desired['info'][2]['week']['videos'][0]['link'] = 'goals.mp4';
$desired['info'][2]['week']['videos'][1]['id'] = 2929793;
$desired['info'][2]['week']['videos'][1]['link'] = 'best.mp4';
$list = array();
$list["info"][0]["player"] = "Messi";
$list["info"][0]["week"]["id"] = "252";
$list["info"][0]["week"]["videos"][0]["id"] = 2929850;
$list["info"][0]["week"]["videos"][0]["link"] = "goals.mp4";
$list["info"][0]["week"]["videos"][1]["id"] = 2929848;
$list["info"][0]["week"]["videos"][1]["link"] = "best.mp4";
$list["info"][0]["week"]["videos"][2]["id"] = 2929847;
$list["info"][0]["week"]["videos"][2]["link"] = "dribbling.mp4";
$list["info"][1]["player"] = "CR7";
$list["info"][1]["week"]["id"] = "251";
$list["info"][1]["week"]["videos"][0]["id"] = 2929796;
$list["info"][1]["week"]["videos"][0]["link"] = "goals.mp4";
$list["info"][1]["week"]["videos"][1]["id"] = 2929795;
$list["info"][1]["week"]["videos"][1]["link"] = "best.mp4";
$list["info"][2]["player"] = "Neymar";
$list["info"][2]["week"]["id"] = "253";
$list["info"][2]["week"]["videos"][0]["id"] = 2929794;
$list["info"][2]["week"]["videos"][0]["link"] = "goals.mp4";
$list["info"][2]["week"]["videos"][1]["id"] = 2929793;
$list["info"][2]["week"]["videos"][1]["link"] = "best.mp4";
$file = array();
$file[252][0]['id'] = 2929850;
$file[252][0]['link'] = 'goals.mp4';
$file[252][1]['id'] = 2929848;
$file[252][1]['link'] = 'best.mp4';
$file[251][0]['id'] = 2929796;
$file[251][0]['link'] = 'goals.mp4';
$file[251][1]['id'] = 2929795;
$file[251][1]['link'] = 'best.mp4';
Edit
function array_diff_assoc_recursive($array1, $array2) {
$difference=array();
foreach ($array1 as $key => $value) {
if (is_array($value)) {
if( !isset($array2[$key]) || !is_array($array2[$key])) {
$difference[$key] = $value;
} else {
$new_diff = array_diff_assoc_recursive($value, $array2[$key]);
if (!empty($new_diff))
$difference[$key] = $new_diff;
}
} else if (!array_key_exists($key,$array2) || $array2[$key] !== $value) {
$difference[$key] = $value;
}
}
return $difference;
}
$new = array('info' => array());
foreach ($list['info'] as $key => $item) {
$a = $item['week']['videos'];
//$b = $file[$item['week']['id']] ?? []; // This is PHP7+
$b = isset($file[$item['week']['id']]) ? $file[$item['week']['id']] : [];
$c = array_diff_assoc_recursive($a, $b);
if (!empty($c)) {
$new['info'][$key] = $item;
$new['info'][$key]['week']['videos'] = $c;
}
}
You will need a function that will check the difference between the videos arrays.
What I do is simply iterate over the list array and then check the difference between that item and the file array. The difference is then stored in $c.
If there is a difference then if statement is fired which will store that player in the $new array and then replace the videos array with the difference array.
This is similar to what you were doing when you were unsetting variables.

How to print the values from an array return by a json response?

I am trying to print a json array into its values I have the following array after json decode and i need to print it in a loop as it has many items.
For e.g i have to print the value firstName, lastName ,how will i print it.
stdClass Object ( [content] => Array ( [0] => stdClass Object ( [id] => 5 [firstName] => Ali [lastName] => S [profilePhotoUrl] => https://prn-spe-images.s3-ap-southeast-1.amazonaws.com/user-profiles/5.jpg [handle] => aliya ) [1] => stdClass Object ( [id] => 69 [handle] => hhtc ) ) [last] => 1 [totalPages] => 1 [totalElements] => 2 [numberOfElements] => 2 [first] => 1 [sort] => [size] => 10 [number] => 0 )
Sample code i have done :
$arrayl = gettviewers($post->id,10);
foreach($arrayl as $valuel) {
print $value1->content->firstName;
}
But it is not printing any value.
### Full working code from the below answers: ###
Helper file:
####### --- Get live viwers list for each broadcast --- ########
if ( ! function_exists('gettviewers'))
{
function gettviewers($broId,$size){
$CI =& get_instance();
$url = API_SERVER.'broadcasts/public/'.$broId.'/top-viewers?size='.$size;
$json = json_decode(file_get_contents($url), true);
return $json;
}
}
In the view:
$arrayl = gettviewers($post->id, WI_LIVEUSERSIZE);
foreach($arrayl as $value1)
{
print $value1[0][firstName];
}
Foreach 'takes' every element of a object or an array. So when you do foreach your $value1 isn't
stdClass Object ( [content] => Array ( [0] => stdClass Object ( [id] => 5 [firstName] => Ali [lastName] => S [profilePhotoUrl] => https://prn-spe-images.s3-ap-southeast-1.amazonaws.com/user-profiles/5.jpg [handle] => aliya ) [1] => stdClass Object ( [id] => 69 [handle] => hhtc ) ) [last] => 1 [totalPages] => 1 [totalElements] => 2 [numberOfElements] => 2 [first] => 1 [sort] => [size] => 10 [number] => 0 )
but is
[content] => Array ( [0] => stdClass Object ( [id] => 5 [firstName] => Ali [lastName] => S [profilePhotoUrl] => https://prn-spe-images.s3-ap-southeast-1.amazonaws.com/user-profiles/5.jpg [handle] => aliya ) [1] => stdClass Object ( [id] => 69 [handle] => hhtc ) ) [last] => 1 [totalPages] => 1 [totalElements] => 2 [numberOfElements] => 2 [first] => 1 [sort] => [size] => 10 [number] => 0
So your $value1 is already [content]. Also you should notice that [content] is an array so you have to do
$arrayl = gettviewers($post->id,10);
foreach($arrayl as $valuel) {
print $value1[0]->firstName;
}
or use second foreach loop inside the first one.
You can achieve this using json_decode
json_decode converts a valid JSON to a stdClass-Object.
Try this:
$arrayl = json_decode(gettviewers($post->id, 10));
foreach($arrayl as $value1)
{
print $value1->content->firstName;
}
try this
$arrayl = gettviewers($post->id,10);
if (is_object($arrayl)) {
// Gets the properties of the given object
// with get_object_vars function
$arrayl = get_object_vars($arrayl);
}
if (is_array($arrayl)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
$arrayl = array_map(__FUNCTION__, $arrayl);
}
else {
// Return array
return $arrayl;
}
var_dump($arrayl) or print_r($arrayl);
or
foreach($arrayl as $key=>$val){
echo $val->content[$key]
}
To print json_encoded array do this
$array=json_decode($data,true); //data is your json_encoded data
foreach($array as $key=>$value)
{
echo $key . ' ' . $value . PHP_EOL;
}
or just do
print_r($array);
after decoding it.

PHP array serialize key value CodeIgniter cache

I have table name 'preferences' column(key,value)
I use cache in codeigniter
look this :
$pref = $this->ci->db->get('preferences')->result();
$this->ci->cache->save('preferences', $pref, 30000);
save cache :
a:3:{s:4:"time";i:1386246188;s:3:"ttl";i:30000;s:4:"data";a:87:{i:0;O:8:"stdClass":2:{s:3:"key";s:10:"site_title";s:5:"value";s:13:"CARS Big";}i:1;O:8:"stdClass":2:{s:3:"key";s:11:"forum_title";s:5:"value";s:14:"CARS Big forum";}i:2;O:8:"stdClass":2:{s:3:"key";s:14:"forum_per_page";s:5:"value";s:2:"10";}...
Call cache use:
$data = $this->ci->cache->get('preferences');
print_r($data);
output:
Array(
[0] => Array
(
[key] => site_title
[value] => CARS Big
)
[1] => Array
(
[key] => forum_title
[value] => CARS Big forum
)
[2] => Array
(
[key] => forum_per_page
[value] => 10
)
[3] => Array
(
[key] => forum_section_per_page
[value] => 10
)
[4] => Array
(
[key] => forum_replies_per_page
[value] => 5
)
[5] => Array
(
[key] => forum_can_add_pictures
[value] => 1
)
[6] => Array
(
[key] => forum_can_add_poll
[value] => 1
)
[7] => Array
(
[key] => forum_can_set_time_to_close
[value] => 1
)
[8] => Array
(
[key] => forum_can_set_replies_to_close
[value] => 1
)
[9] => Array
(
[key] => forum_auto_active_topics
[value] => 1
)
[10] => Array
(
[key] => market_title
[value] => market CARS Big
)
[11] => Array
(
[key] => market_per_page
[value] => 5
)
[12] => Array
(
[key] => market_section_per_page
[value] => 3
)
)
How do I make the content of the column key is the key
And the column value is the content
Like this:
$data['site_title']
I need $data['site_title'] to print : CARS Big
so as to call this function
function pref($key=NULL)
{
$data = $this->ci->cache->get('preferences');
return $data[$key];
}
**
Essentially you are looking to loop the values and re-assign the keys so something like this could work:
// loop through data
foreach($data as $k=>$v)
{
// unset the original array item to get rid of $data[0], $data[1], $data[2] as so forth
unset($data[$k]);
// $k is a digit (0,1,2,3,4,5,....)
// $v is the array of values so $v['key'] is 'site_title' and $v['value'] is 'CARS Big'
// so essentially we are doing $data['site_title'] = 'CARS Big'; in the line below
$data[$v['key']] = $v['value'];
}
you can't, since the cache save implementation is a fixed process. only if you make your own cache implementation.
but you can perform your return function like this
function pref($key=NULL)
{
// call pref data
$data = $this->ci->cache->get('preferences');
if( ! $data ) {
// cache not present request new
$data = $this->ci->db->get('preferences')->result();
$this->ci->cache->save('preferences', $data, 30000);
}
// loop
foreach( $data as $preferences ) {
if( isset( $preferences['key'] ) && $preferences['key'] == $key ){
return $preferences['value'];
}
}
return false;
}

Getting data from SimpleDB using PHP

How do I get data out of SimpleDB? All I wanted to do was put data in and then get data out. It looks like the data is not easy to get out and in the end will require computing power to extract by looping etc. Am I correct?
Here is my code to extract the data:
<?php
// Include the SDK
require_once 'sdk.class.php';
// Instantiate
$sdb = new AmazonSDB();
$select_expression = 'SELECT * FROM ' . $domain_name;
$next_token = null;
do {
if ($next_token) {
$response = $sdb->select($select_expression, array(
'NextToken' => $next_token,
));
} else {
$response = $sdb->select($select_expression);
}
// Get Data for row
$body = $response->body->to_array()->getArrayCopy();
echo "ID: " . $msgId . "<br>";
$next_token = isset($response->body->SelectResult->NextToken)
? (string) $response->body->SelectResult->NextToken
: null;
}
while ($next_token);
echo "<br>";
?>
Here is the extract of the data I'm trying to extract.
Array
(
[#attributes] => Array
(
[ns] => http://sdb.amazonaws.com/doc/2009-04-15/
)
[SelectResult] => Array
(
[Item] => Array
(
[0] => Array
(
[Name] => 1
[Attribute] => Array
(
[0] => Array
(
[Name] => msgAddress
[Value] => +2782555555
)
[1] => Array
(
[Name] => msgType
[Value] => S
)
[2] => Array
(
[Name] => msgSubmitDate
[Value] => 2012-09-02 15:48:46
)
[3] => Array
(
[Name] => msgText
[Value] => Test SMS message for ID no 1
)
)
)
[1] => Array
(
[Name] => 2
[Attribute] => Array
(
[0] => Array
(
[Name] => msgAddress
[Value] => +27825555555
)
[1] => Array
(
[Name] => msgType
[Value] => P
)
[2] => Array
(
[Name] => msgSubmitDate
[Value] => 2012-09-02 15:48:46
)
[3] => Array
(
[Name] => msgText
[Value] => Test phone message for ID no 2
)
)
)
[2] => Array
(
[Name] => 3
[Attribute] => Array
(
[0] => Array
(
[Name] => msgAddress
[Value] => name#domain.co.za
)
[1] => Array
(
[Name] => msgType
[Value] => E
)
[2] => Array
(
[Name] => msgSubmitDate
[Value] => 2012-09-02 15:48:46
)
[3] => Array
(
[Name] => msgText
[Value] => Test email message for ID no 3 to name#domain.co.za
)
)
)
[3] => Array
(
[Name] => 4
[Attribute] => Array
(
[0] => Array
(
[Name] => msgAddress
[Value] => andrebruton
)
[1] => Array
(
[Name] => msgType
[Value] => P
)
[2] => Array
(
[Name] => msgSubmitDate
[Value] => 2012-09-02 15:48:46
)
[3] => Array
(
[Name] => msgText
[Value] => Test push notification message for ID no 4
)
)
)
)
)
)
All I want to get is the following variables:
msgId (the Name), msgType, msgAddress, msgText, msgSubmitDate
If I can get it using $msgType = Body->SelectResult->Item->Name or something like that.
Using XPath is going to perform about 100x faster. I haven't tested this code, but the XPath expression should be pretty close:
$msgAddress = (string) $response->body->query('//Attribute[Name[text()="msgAddress"]]/Value')->first();
I figured it out using some old Tarzan code. This works for a 2 dimensional array (data similar to a standard database)
Here is the working code:
<?php
// Include the SDK
require_once 'sdk.class.php';
// Instantiate
$sdb = new AmazonSDB();
$select_expression = 'SELECT * FROM ' . $domain_name;
$next_token = null;
do {
if ($next_token) {
$response = $sdb->select($select_expression, array(
'NextToken' => $next_token,
));
} else {
$response = $sdb->select($select_expression);
}
// Get Data for row
foreach ($response->body->SelectResult->Item as $item)
{
$msgId = $item->Name;
foreach ($item->Attribute as $attr)
{
if ($attr->Name == 'msgAddress') {
$msgAddress = $attr->Value;
}
if ($attr->Name == 'msgType') {
$msgType = $attr->Value;
}
if ($attr->Name == 'msgSubmitDate') {
$msgSubmitDate = $attr->Value;
}
if ($attr->Name == 'msgText') {
$msgText = $attr->Value;
}
}
echo "<br>msgId: $msgId<br>";
echo "msgAddress: $msgAddress<br>";
echo "msgType: $msgType<br>";
echo "msgSubmitDate: $msgSubmitDate<br>";
echo "msgText: $msgText<br><br>";
}
$next_token = isset($response->body->SelectResult->NextToken)
? (string) $response->body->SelectResult->NextToken
: null;
}
while ($next_token);
echo "<br>";
?>
$body = $response->body->to_array()->getArrayCopy();
echo "ID: " . $msgId . "<br>";
//but $msgId is not set

How do you add to a new index on a Multi-dimensional array within a foreach loop?

Hell once again, I am wondering how do you go about adding data to a new array index when inside a foreach loop?
the code I have atm is,
// Connect to the database to gather all data pertaiing to the link in question
$assoResult = mysql_query("SELECT * FROM associate_users");
while ($assoRow = mysql_fetch_field($assoResult)) {
$resultArray[] = $assoRow->name;
}
// Connect to the database to gather all data pertaiing to the link in question
$assoResult2 = mysql_query("SELECT * FROM associate_users WHERE id='$getID'");
while ($assoRow2 = mysql_fetch_object($assoResult2)) {
foreach ($resultArray as $row) {
$array = array(array( 1 => $assoRow2->$row, 2 => $row, ),);
echo "<br />"; print_r($array);
}
}
Below is the outputted data that comes from the "echo "br />"; print_r($array);" line.
=================================================================
Array ( [0] => Array ( [1] => 1 [2] => id ) )
Array ( [0] => Array ( [1] => Bob[2] => contactName ) )
Array ( [0] => Array ( [1] => Bob's Tyres [2] => company ) )
Array ( [0] => Array ( [1] => XXXXXXXXXXXXXX [2] => address1 ) )
Array ( [0] => Array ( [1] => XXXXXXXXXXXXXX [2] => address2 ) )
Array ( [0] => Array ( [1] => XXXXXXXXX [2] => address3 ) )
Array ( [0] => Array ( [1] => XXXXXX [2] => postcode ) )
As you can see the array is being created a new over and over, what I need is for the above data to increment the 1st dimension index key on every loop, so it looks like...
=================================================================
Array ( [0] => Array ( [1] => 1 [2] => id ) )
Array ( [1] => Array ( [1] => Bob[2] => contactName ) )
Array ( [2] => Array ( [1] => Bob's Tyres [2] => company ) )
Array ( [3] => Array ( [1] => XXXXXXXXXXXXXX [2] => address1 ) )
Array ( [4] => Array ( [1] => XXXXXXXXXXXXXX [2] => address2 ) )
Array ( [5] => Array ( [1] => XXXXXXXXX [2] => address3 ) )
Array ( [6] => Array ( [1] => XXXXXX [2] => postcode ) )
Thank you in advance I am out of all options in getting this to work and desperate.
Dan.
Change the values assigning part of your code to
$count=0;
foreach ($resultArray as $row) {
$array[$count][1] = $assoRow2->$row
$array[$count][2]=$row;
$count++;
echo "<br />"; print_r($array);
}
This code gets you the output you asked for without inefficiently using two queries:
// Connect to the database to gather all data pertaining to the link in question
$result = mysql_query("SELECT * FROM associate_users WHERE id=" . (int)$getID);
$resultArray = array();
$resultCount = 0;
$row = mysql_fetch_assoc($result);
$count = 0;
foreach ($row as $key => $value) {
$temp = array();
$temp[$count] = array(1 => $value, 2 => $key);
$count++;
echo "<br />"; print_r($temp);
}
Why you want it like this, I have no idea.
//extra code.declaring array
$array = array();
while ($assoRow2 = mysql_fetch_object($assoResult2)) {
foreach ($resultArray as $row) {
// 1st parameter is the array name, here array name is array .give gd name according to use
array_push($array,array( 1 => $assoRow2->$row, 2 => $row, ));
echo "<br />"; print_r($array);
}
}

Categories