mysql cant save my big decimal number - json

I have a number like this
34.59704151614417
and I put datatype on decimal(16,14) but it has saved as 34.59704151614400
it means mysql save just 12 digit decimal
this is my array
Array
(
[geometry] => Array
(
[type] => Polygon
[coordinates] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 32.34375
[1] => 48.690960390925
)
[1] => Array
(
[0] => 16.875
[1] => 34.597041516144
)
[2] => Array
(
[0] => 43.2421875
[1] => 31.653381399664
)
[3] => Array
(
[0] => 64.3359375
[1] => 40.97989806962
)
[4] => Array
(
[0] => 32.34375
[1] => 48.690960390925
)
)
)
)
)
I understand
after I do json_decode of my array it reduce it's digit to 12 number

Set precision directive:
ini_set('precision', 16);
It is currently 14 and that's why the decimals get reduced. Check this link about more information

Related

how to combine mysql query in CodeIgniter

I need to combine those two array into a single array.
1st query result
Array ( [0] => stdClass Object ( [p_type] => Bank [tsales] => 131000 [tdues] => 55000 [tpaid] => 75000 ) [1] => stdClass Object ( [p_type] => Cash [tsales] => 104000 [tdues] => 50000 [tpaid] => 54000 ) [2] => stdClass Object ( [p_type] => bKash [tsales] => 25000 [tdues] => 10000 [tpaid] => 5000 ) [3] => stdClass Object ( [p_type] => Pause [tsales] => 4000 [tdues] => 1000 [tpaid] => 2000 ) )
2nd query result
Array ( [0] => stdClass Object ( [dpayment] => 1000 ) [1] => stdClass Object ( [dpayment] => 5000 ) [2] => stdClass Object ( [dpayment] => 1000 ) [3] => stdClass Object ( [dpayment] => 5000 ) )
try to use array_merge. That should be very easy.
Your query result shows that you using $query->result() to get the value,
Instead of using result(), use $query->row_array();
then you get single dimensional array for both queries
then use array_merge() that would be easy

How to read youtube data api v3 response in php

I have following code:
$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));
That returns the following output:
Google_Service_YouTube_ChannelListResponse Object
(
[collection_key:protected] => items
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/sTnuE1bHO-tokx_mFFDt1ybN90g"
[eventId] =>
[itemsType:protected] => Google_Service_YouTube_Channel
[itemsDataType:protected] => array
[kind] => youtube#channelListResponse
[nextPageToken] =>
[pageInfoType:protected] => Google_Service_YouTube_PageInfo
[pageInfoDataType:protected] =>
[prevPageToken] =>
[tokenPaginationType:protected] => Google_Service_YouTube_TokenPagination
[tokenPaginationDataType:protected] =>
[visitorId] =>
[modelData:protected] => Array
(
[pageInfo] => Array
(
[totalResults] => 1
[resultsPerPage] => 1
)
[items] => Array
(
[0] => Array
(
[kind] => youtube#channel
[etag] => "WFPuK6TsnblcGPcnMex79s42ynQ/ecOcHFmWyWQ7ToCD7-B1L36b4L4"
[id] => UCQO6uXy5maTpYvSa_yM--Bw
[brandingSettings] => Array
(
[channel] => Array
(
[title] => Vasim Padhiyar
[showRelatedChannels] => 1
[featuredChannelsTitle] => Featured Channels
[featuredChannelsUrls] => Array
(
[0] => UCw-TnDmYDQyjnZ5qpVWUsSA
)
[profileColor] => #000000
)
[image] => Array
(
[bannerImageUrl] => http://s.ytimg.com/yts/img/channels/c4/default_banner-vfl7DRgTn.png
)
[hints] => Array
(
[0] => Array
(
[property] => channel.featured_tab.template.string
[value] => Everything
)
[1] => Array
(
[property] => channel.banner.image_height.int
[value] => 0
)
[2] => Array
(
[property] => channel.modules.show_comments.bool
[value] => True
)
)
)
)
)
)
[processed:protected] => Array
(
)
)
I want to loop through modelData:protected variable to get the list of channels and its items data. Its json object so $yt_profiles->modelData:protected not working while accessing. Please help me to solve this issue.
Thanks in advance
You can reach it as in an array:
print_r ($yt_profiles['modelData']);
Your request:
$yt_profiles = $youtube->channels->listChannels('brandingSettings', array(
'mine' => 'true',
));
To acces to values Channel title for example:
$titleChannel = $yt_profiles["items"][0]["brandingSettings"]["channel"]["title"];
To acces to values bannerImageUrl for example:
$banner = $yt_profiles["items"][0]["brandingSettings"]["image"]["bannerImageUrl"];
Does this help you?
$yt_profiles = $youtube->channels->listChannels('id, brandingSettings', array('mine' => 'true',));
foreach ($yt_profiles['modelData']['items'] as $searchResult) {
switch ($searchResult['kind']) {
case 'youtube#channel':
$channels[]= array('id'=> $searchResult['id'],
'brandingSettings'=> $searchResult['brandingSettings']);
break;
}
}

Combine 3 arrays into One

I have 3 Queries
$this->db->select('count(id) as Lead_Current_Month')->from('admin_lead_distribution');
$result1=$this->db->get()->result();
$this->db->select('count(id) as Lead_Current_Month')->from('level1_lead_distribution');
$result2=$this->db->get()->result();
$this->db->select('count(id) as Lead_Current_Month')->from('level2_lead_distribution');
$result3=$this->db->get()->result();
When I print it gives
Array
(
[0] => stdClass Object
(
[Lead_Current_Month] => 12
)
)
Array
(
[0] => stdClass Object
(
[Lead_Current_Month] => 38
)
)
Array
(
[0] => stdClass Object
(
[Lead_Current_Month] => 10
)
)
How to combine 3 arrays into one?
I want the result to be:
Array
(
[0] => stdClass Object
(
[Lead_Current_Month] => 60
)
)
[Lead_Current_Month] => 60(60 is sum all the 3 array values)
You can just sum up the values of the results, and I don't know why you want to store the information in any array/object, just store it in a variable.
$sum_result = $result1[0]->Lead_Current_Month + $result2[0]->Lead_Current_Month + $result3[0]->Lead_Current_Month;
echo $sum_result; //will echo 60

Sort array (stdClass Object)

Getting this result after array_merge of 2 arrays:
Array ( [0] => stdClass Object ( [tid] => 3954 [name] => Alleman )
[1] => stdClass Object ( [tid] => 3958 [name] => Jack )
[2] => stdClass Object ( [tid] => 3963 [name] => Aquin Catholic ));
I want to sort the array by [name]. I have been reading and searching for hours but cannot figure out how to sort passed the stdClass Object to [name].
Have tried sort, ksort, uasort, etc. wont sort passed the stdClass Object to [name].
Example
function compareItems($a, $b)
{
if ( $a->name < $b->name ) return -1;
if ( $a->name > $b->name ) return 1;
return 0; // equality
}
uasort($players, "compareItems");

How to order sql results by counting a field in CakePHP 2.0

When I perform the following:
$popular_posts = $this->Blog->find('all', array('limit' => 5));
I get the following:
Array
(
[0] => Array
(
[Blog] => Array
(
[id] => 4fcfb37d-3eb0-4ec2-a744-175c987a2b72
[title] => This is a post example2
[short_description] => You've stumbled across our blog! Welcome! Here
[created] => 2012-06-06 21:46:05
[modified] => 2012-06-07 16:01:24
)
[Reply] => Array
(
[0] => Array
(
[id] => 4fcfb305-0c58-421b-9149-175c987a2b72
)
[1] => Array
(
[id] => 4fd0ae9e-dca0-4afe-862c-1258987a2b72
)
)
),
[1] ...
[2] ...
)
How can I order the results by the number of Reply ??? (desc)?
Try this
$data = $this->Blog->find('all',array('group' =>array('Reply.id'),
'order' => array('COUNT(Reply.id) DESC'),
'limit'=> 5));