regarding in query from the model, i got already the values and store it from a variable, now i want it to be stored from a data array for further use, how can i do this, i am in controller from codeigniter.
Here is my controller full code:
public function move_data($queue_id) {
$data = array();
$user = array('user_id' => $this->session->userdata['logged_in']['user_id']);
$getqueuedata = $this->Clinic_model->queue_data($queue_id,$user);
//echo json_encode($getqueuedata);
$data = array (
'queue_id' => $getqueuedata['queue_id'],
'user_id' => $getqueuedata['user_id'],
'clinic_id' => $getqueuedata['clinic_id'],
'order_num' => $getqueuedata['order_num'],
'patient_id' => $getqueuedata['patient_id'],
);
}
when i //echo json_encode($getqueuedata); uncomment this line, and comment the array storing, i will have this:
[{"user_id":"102","clinic_id":"2","order_num":"1","patient_id":"7","status":"2","time_sched":null,"queue_id":"1"}]
in my full code, i got error, i dont know how to store the values of my query from array.
function 'queue_data` return result like this :
//$getqueuedata = json_decode($json,true);
Array ( [0] => Array ( [user_id] => 102 [clinic_id] => 2 [order_num] => 1 [patient_id] => 7 [status] => 2 [time_sched] => [queue_id] => 1 ) )
So you can store data as this way:
$data = array (
'queue_id' => $getqueuedata[0]['queue_id'],
'user_id' => $getqueuedata[0]['user_id'],
'clinic_id' => $getqueuedata[0]['clinic_id'],
'order_num' => $getqueuedata[0]['order_num'],
'patient_id' => $getqueuedata[0]['patient_id'],
);
print_r($getqueuedata);
If your function return array object:
$data = array (
'queue_id' => $getqueuedata[0]->queue_id,
'user_id' => $getqueuedata[0]->user_id,
'clinic_id' => $getqueuedata[0]->clinic_id,
'order_num' => $getqueuedata[0]->order_num,
'patient_id' => $getqueuedata[0]->patient_id,
);
Related
I am trying to add my data to my array inside my foreach loop.
I have almost done it successfully, except the array is too in-depth.
It's showing array->array->{WHAT I WANT}
When I need array->{WHAT I WANT}
Example, I'm needing it to be like:
Array
(
[home] => Array
(
[0] => Dashboard\Main#index
[1] => GET
)
[home/] => Array
(
[0] => Dashboard\Main#index
[1] => GET
)
)
When at the moment, it's showing:
Array
(
[0] => Array
(
[services/content-writing] => Array
(
[0] => Dashboard\Services#contentwriting
[1] => GET
)
)
[1] => Array
(
[services/pbn-links] => Array
(
[0] => Dashboard\Services#pbnlinks
[1] => GET
)
)
)
The code I'm currently using inside my foreach loop is:
$realArray = array();
// Services exist
if($services)
{
// Sort them into our array
foreach ($services as $service) {
$servicePageName = $service->page_name;
$serviceName = str_replace(' ', '', strtolower($service->name));
$realArrayNew = array(
"services/$servicePageName" => ["Dashboard\Services#$serviceName", 'GET']
);
array_push($realArray, $realArrayNew);
//'home' => ['Dashboard\Main#index', 'GET'],
}
}
return $realArray;
The servicePageName variable must be the key field on the realArray to get the results you want.
I'm presuming you input object array looks something like this:
[
(int) 0 => object(stdClass) {
name => 'contentwriting'
page_name => 'content-writing'
},
(int) 1 => object(stdClass) {
name => 'pbnlinks'
page_name => 'pbn-links'
}
]
If we do this:
$realArray = [];
if ($services) {
foreach ($services as $service) {
$servicePageName = $service->page_name;
$serviceName = str_replace(' ', '', strtolower($service->name));
$realArray["services/$servicePageName"] = [
0 => "Dashboard\Services#$serviceName",
1 => "GET"
];
}
}
This is what we get on realArray:
[
'services/content-writing' => [
(int) 0 => 'Dashboard\Services#contentwriting',
(int) 1 => 'GET'
],
'services/pbn-links' => [
(int) 0 => 'Dashboard\Services#pbnlinks',
(int) 1 => 'GET'
]
]
This portion of the code inserts a new subarray to your main array:
$realArrayNew = array(
"services/$servicePageName" => ["Dashboard\Services#$serviceName", 'GET']
);
array_push($realArray, $realArrayNew);
Replace it all with:
$realArray["services/$servicePageName"] = ["Dashboard\Services#$serviceName", 'GET'];
That way your top level will have service names as keys.
I have an Array Object which I would like to print as an Associative Array
<?php
require_once(dirname(__FILE__) . '/HarvestAPI.php');
/* Register Auto Loader */
spl_autoload_register(array('HarvestAPI', 'autoload'));
$api = new HarvestAPI();
$api->setUser( $user );
$api->setPassword( $password );
$api->setAccount( $account );
$api->setRetryMode( HarvestAPI::RETRY );
$api->setSSL(true);
$result = $api->getProjects(); ?>
It should print something like this.
Array ( [] => Harvest_Project Object (
[_root:protected] => project
[_tasks:protected] => Array ( )
[_convert:protected] => 1
[_values:protected] => Array (
[id] => \
[client-id] => -
[name] => Internal
[code] =>
[active] => false
[billable] => true
[bill-by] => none
[hourly-rate]=>-
How can I achieve this?
Update
I tried doing a varexport. But it gives something like this
Harvest_Result::__set_state(array( '_code' => 200, '_data' => array ( 5443367 => Harvest_Project::__set_state(array( '_root' => 'project', '_tasks' => array ( ), '_convert' => true, '_values' => array ( 'id' => '564367', 'client-id' => '2427552', 'name' => 'Internal', 'code' => '', 'active' => 'false', 'billable' => 'tr
This is not what I am looking for. The object should clearly list the fields it has.
If there's a need to get visibility types as well in the string representation of the object's properties, it can be solved quite simply with ReflectionClass:
$arrayObj = new Harvest_Project();
$reflection = new \ReflectionClass($arrayObj);
$objStr = '';
$properties = $reflection ->getProperties();
foreach ($properties as $property)
{
if ($property->isPublic()) $propType = 'public';
elseif ($property->isPrivate()) $propType = 'private';
elseif ($property->isProtected()) $propType = 'protected';
else $propType = 'static';
$property->setAccessible(true);
$objStr .= "\n[{$property->getName()} : $propType] => " . var_export($property->getValue($arrayObj), true) .';';
}
var_dump($objStr);
The output looks like this:
[_foobar : private] => 42;
[_values: protected] => array (
0 => 'foo',
1 =>
array (
0 => 'bar',
1 => 'baz',
),
);
Warning getProperties might not get inherited properties depending on the PHP version; in this case see examples of how to recursively get them all here.
this is my reply
Array ([code] => 202 [message] => Accepted [data] => Array ( [resultMap] => Array ( [D3856~H158] => Array ( [AppDay] => * [HosTown] => Colombo 06 [SpecName] => Physiotherapist/Sports Physiotherapist [HosName] => Revival Healthcare Services (Pvt)-Colombo [SpecializationId] => 333 [HosCode] => H158 [AppDate] => Any [DocName] => MR CHAMARA MATHANGAWEERA [DoctorNo] => D3856 ) ) ) [detailMessage] => Success )
now i want to assign variable for this vale and echo in proper way i try this
but it is giving a error msg
Undefined index: DocName
this is my code
////////////////////////////////////
if( $response ){
if ( isset($result->error) )die( $result->error_message );
/* Convert json data to array */
$arr=json_decode( $response, true );
//print_r($arr);
foreach($arr['data'] as $data)
{
$output="Doctor".$data['DocName']."<br/>";
$output="Doctor".$data['SpecName']."<br/>";
$output="Doctor".$data['HosName']."<br/>";
$output="Doctor".$data['Day']."<br/>";
$output="Doctor".$data['Date']."<br/>";
}
Have a look at the structure of your array. The values you are looking for are nested withing several arrays:
$data = array (
'code' => 202,
'message' => 'Accepted',
'data' => array (
'resultMap' => array (
'D3856~H158' => array (
'AppDay' => '*',
'HosTown' => 'Colombo 06',
'SpecName' => 'Physiotherapist/Sports Physiotherapist',
'HosName' => 'Revival Healthcare Services (Pvt)-Colombo',
'SpecializationId' => 333,
'HosCode' => 'H158',
'AppDate' => 'Any',
'DocName' => 'MR CHAMARA MATHANGAWEERA',
'DoctorNo' => 'D3856',
)
)
),
'detailMessage' => 'Success'
);
To print all values for the first record in resultMap:
foreach(current($data['data']['resultMap']) as $key => $value) {
echo $key . " => " . $value . "<br />";
}
You need an additional loop in order to print all records in resultMap.
You can try this working fine
for this fixed array values means below given
foreach($arr['data']['resultMap']['D3856~H158'] as $data)
{
$output="Doctor".$data['DocName']."<br/>";
$output="Doctor".$data['SpecName']."<br/>";
$output="Doctor".$data['HosName']."<br/>";
$output="Doctor".$data['Day']."<br/>";
$output="Doctor".$data['Date']."<br/>";
}
or
The changing array values are given the answer
foreach($arr['data']['resultMap'] as $data)
{
$output="Doctor".$data['DocName']."<br/>";
$output="Doctor".$data['SpecName']."<br/>";
$output="Doctor".$data['HosName']."<br/>";
$output="Doctor".$data['Day']."<br/>";
$output="Doctor".$data['Date']."<br/>";
}
Sorry for the title of my question. It is hard for me to explain this so to make my problem short.
I just need to pass the values from my table to my function. I put the information from my table in an array and I need to use that array because it will serve it as the parameter for my function.
Here's the sample code.
$dragonpay = "SELECT * FROM dragon_pay";
$resultDragonPay = $this->db->query($dragonpay);
foreach($resultDragonPay->result_array() as $dragonpay_value){
$dragon[] = array(
'transaction_id' => $dragonpay_value['transaction_id'],
'SC_REF' => $dragonpay_value['SC_REF']
);
}
This is the sample output using print_r($dragon)
Array
(
[0] => Array
(
[transaction_id] => 122451
[SC_REF] => LL877KG4
)
[1] => Array
(
[transaction_id] => 122563
[SC_REF] => ERQKX2A0
)
[2] => Array
(
[transaction_id] => 122696
[SC_REF] => AM383D62
)
[3] => Array
(
[transaction_id] => 123549
[SC_REF] => E88JNWB6
)
[4] => Array
(
[transaction_id] => 122407
[SC_REF] => 734T3AK3
)
[5] => Array
(
[transaction_id] => 123352
[SC_REF] => QFL45SM2
)
Now my problem is the values from my array. Each of the index values should be use as a parameter.
Now I have this function. The use of this function is for data encryption.
$info_data = #serialize($array_here);
$encrypt_data = fn_encrypt_text($info_data);
Example scenario:
$array_to_enrypt = array(
'name' => 'myname',
'gender' => 'mygender'
)
$info_data = #serialize($array_to_enrypt);
$encrypt_data = fn_encrypt_text($info_data);
But I included all the values from my array. How can I get every value and use this as a single array? Do I need to include this in the loop? That's all guys I hope you understand what I mean. Thanks.
Is this what you need?
function dragon_pay(){
$data = $this->db->get('dragon_pay')->result_array();
if( is_array( $data ) && count( $data ) > 0 ){
foreach( $data as $key => $each ){
$dragon = array(
'transaction_id' => $dragonpay_value['transaction_id'],
'SC_REF' => $dragonpay_value['SC_REF']
);
$info_data = #serialize($dragon);
$encrypt_data = fn_encrypt_text($info_data);
call_to_another_function( $encrypt_data ); #this is the function you want to call with the encrypted text?
}
}
print_r( $data );
}
I have one multidimensional array as shown below(PHP) :
Array
(
[144320] => Array
(
[3568728] => Array
(
[30832] => 30832
)
[3568884] => Array
(
[30827] => 30827
[30828] => 30828
[30830] => 30830
[30831] => 30831
[30832] => 30832
[30837] => 30837
[30838] => 30838
[30839] => 30839
[30826] => 30826
[30808] => 30808
[30806] => 30806
[30807] => 30807
[30698] => 30698
[30601] => 30601
[30697] => 30697
)
)
[144330] => Array
(
[3568731] => Array
(
[30827] => 30827
[30839] => 30839
[30838] => 30838
[30837] => 30837
[30832] => 30832
[30831] => 30831
[30828] => 30828
[30830] => 30830
[30826] => 30826
[30806] => 30806
[30808] => 30808
[30807] => 30807
[30698] => 30698
[30697] => 30697
[30601] => 30601
)
)
[144218] => Array
(
[3568753] => Array
(
[30808] => 30808
)
)
[144216] => Array
(
[3568732] => Array
(
[30808] => 30808
)
)
)
This array is populated by following code:
$sql = "SELECT * FROM `bf_alert_stack` WHERE `type` = 'immediately' order by created desc";
$q = db_query($sql);
$user_alerts = array();
while ($row = db_fetch_array($q))
{
$user_alerts [$row['uid']] [$row['alert_id']] [$row['nid']] = $row['nid'];
}
From the above user_alerts array I want to rearrange the [$row['nid']] array and for rearrangement I want capture [$row['nid']] array and after capturing it into another array I want to re-arrange $row['nid'] array I want to update this $row['nid'] array into original user_alerts array.
How I can do this? I am not getting any search for this on google so just placed this on appropriate place.
The best you can do is to get it ordered from the query with something like:
SELECT * FROM `bf_alert_stack` WHERE `type` = 'immediately'
ORDER BY created desc, nid
But if you don't have access, or need the original sort for other reason, you need to iterate recursively over the array and reassign the last sortered level to the original array with PHP ksort method:
http://www.php.net/manual/en/function.ksort.php
foreach($user_alerts as $uid=>$user_alert) {
foreach($alert as $alert_id=>$nids) {
$user_alerts[$uid][$alert_id] = ksort($nids);
}
}
Hope it helps!