cakephp how to group file data when upload multiple file - cakephp-2.2

I use cakephp FormHelper to generate html form code.
echo $this->Form->create('newGallery.', array('type'=>'file'));
echo $this->Form->input('Photos',array(
'type' => 'file',
'label' => 'Photos (jpg,png,gif)',
'name' => 'upload[]',
'required',
'multiple'
));
echo $this->Form->end('Create');
but result is
Array
(
[upload] => Array
(
[name] => Array
(
[0] => Pic1.jpg
[1] => Pic2.jpg
)
[type] => Array
(
[0] => image/jpeg
[1] => image/jpeg
)
[tmp_name] => Array
(
[0] => C:\wamp\tmp\phpB073.tmp
[1] => C:\wamp\tmp\phpB084.tmp
)
[error] => Array
(
[0] => 0
[1] => 0
)
[size] => Array
(
[0] => 216302
[1] => 107102
)
)
)
I need to group the data of the same file so that i can deal with by using foreach loop. This is the result i need
Array
(
[upload] => Array
(
[0] => Array
(
[name] => Pic1.jpg
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\phpB073.tmp
[error] => 0
[size] => 216302
)
[1] => Array
(
[name] => Pic2.jpg
[type] => image/jpeg
[tmp_name] => C:\wamp\tmp\phpB084.tmp
[error] => 0
[size] => 107102
)
)
)
Thank you indeed for your help.

I think this can help you :)
/* create new empty array */
$result=array();
/* create new index */
$i=0;
/* foreach in your $upload or other array */
foreach($upload['upload'] as $key => $val){
foreach($val as $sub_val){
$result[$i][$key]=$sub_val;
$i++;
}
$i=0;
}

Related

How to interpret vin/vout on a Bitcoin transaction?

I used nownodes api to get this response on a transaction:
(
[txid] => 38ac1348219f8aa9349f497bfa6f8d05f775cafbbd26354867d22ca84f15e1e1
[version] => 2
[vin] => Array
(
[0] => stdClass Object
(
[txid] => 38cff250be850140644a1abf022b22f3e59cab15c6091706c3f73218a4d72050
[vout] => 1
[sequence] => 4294967295
[n] => 0
[addresses] => Array
(
[0] => 1EJtMFThodiQ1j26xy1kugFck9325C38CQ
)
[isAddress] => 1
[value] => 158316
[hex] => 4830450221009548f997389fd9881dfed78fe25fcce77f5b96d1545da91dfa13f56db3c02f6e02207fe239ac7916681edc36afd6a9a569981cd12c2c6801616bc15794be5c024431012102afe2e887e3ff56edcebe6b1aa6bf48f4a5a7f02cfc8d743e778896df2054adee
)
)
[vout] => Array
(
[0] => stdClass Object
(
[value] => 7000
[n] => 0
[hex] => a9144a09be6e2917ef00e5d72bc38035db5c5a5ed8ec87
[addresses] => Array
(
[0] => 38SVbkkFE8qcJuGyTJ9fY2cbGS3xknEfYr
)
[isAddress] => 1
)
[1] => stdClass Object
(
[value] => 146856
[n] => 1
[hex] => 76a91491fb9214e6ad9b3ea19c1fd7d3a646e12f804d2688ac
[addresses] => Array
(
[0] => 1EJtMFThodiQ1j26xy1kugFck9325C38CQ
)
[isAddress] => 1
)
)
[blockHash] => 000000000000000000050bfb2a645a5eb7ac882aeb1782bce37ef6a2652c383b
[blockHeight] => 743696
[confirmations] => 8
[blockTime] => 1657005608
[value] => 153856
[valueIn] => 158316
[fees] => 4460
[hex] => 02000000015020d7a41832f7c3061709c615ab9ce5f3222b02bf1a4a64400185be50f2cf38010000006b4830450221009548f997389fd9881dfed78fe25fcce77f5b96d1545da91dfa13f56db3c02f6e02207fe239ac7916681edc36afd6a9a569981cd12c2c6801616bc15794be5c024431012102afe2e887e3ff56edcebe6b1aa6bf48f4a5a7f02cfc8d743e778896df2054adeeffffffff02581b00000000000017a9144a09be6e2917ef00e5d72bc38035db5c5a5ed8ec87a83d0200000000001976a91491fb9214e6ad9b3ea19c1fd7d3a646e12f804d2688ac00000000
)
The transaction was for: 0.0001146 BTC
And the fee was: 0.0000446
Totalling: 0.0001592
However, based on teh result from Nownodes, how can I see what the transaction total was? I can easily see the fee under "Fees". But how do I calculate the actually amount that came in or went out for this transaction?
Thanks!
valueIn = vout[0][value] + vout[1][value] + [fees]
valueIn = 158316
Is that what you have been looking for?

How do i insert multiple rows to a specific postmeta

I am trying update multiple wordpress postmeta fields in one query.
Fields
$fields = [
'token' => $car_hash,
'historie' => $car_history,
'korrekt' => $car_correct,
'kilometer' => $car_km,
'brand' => $car_brand,
'model' => $car_model,
'post_nummer' => $user_zip,
'navn' => $user_name,
'telefon' => $user_phone,
'email' => $user_mail,
'datetime' => $user_datetime,
'customer_city' => $city,
'customer_country' => $country,
'customer_lat' => $lattitude,
'customer_lng' => $longitude
];
Old code which execute a query by using the key value pair in the fields array above.
foreach($fields as $key => $value){
update_field($key, $value, $id);
}
I have been trying to use wpdb::update but i think i am misunderstanding something.
$fields = [
'token' => $car_hash,
'historie' => $car_history,
'korrekt' => $car_correct,
'kilometer' => $car_km,
'brand' => $car_brand,
'model' => $car_model,
'post_nummer' => $user_zip,
'navn' => $user_name,
'telefon' => $user_phone,
'email' => $user_mail,
'datetime' => $user_datetime,
'customer_city' => $city,
'customer_country' => $country,
'customer_lat' => $lattitude,
'customer_lng' => $longitude
];
$tab = 'solgt_postmeta';
$len = count($fields);
$arg = [];
$for = [];
foreach($fields as $key => $value){
$arg[$key] = $value;
$for[] = '%s';
$cnt++;
}
global $wpdb;
if($wpdb->update($tab, $arg, $for)){
echo 'success';
} else {
echo 'error';
}
The formats array look like this
Array
(
[0] => %s
[1] => %s
[2] => %s
[3] => %s
[4] => %s
[5] => %s
[6] => %s
[7] => %s
[8] => %s
[9] => %s
[10] => %s
[11] => %s
[12] => %s
[13] => %s
[14] => %s
);
The arguments array look like this
Array
(
[token] => xxx
[historie] => xxx
[korrekt] => xxx
[kilometer] => xxx
[brand] => xxx
[model] => xxx
[post_nummer] => xxx
[navn] => xxx
[telefon] => xxx
[email] => xxx
[datetime] => xxx
[customer_city] => xxx
[customer_country] => xxx
[customer_lat] => xxx
[customer_lng] => xxx
);
I dont normally use wordpress, and i am confused on how to achieve this without having to do so many queries.
Just use update_post_meta() instead of wpdb::update
<?php
update_post_meta( <post_id>,
'token' , $car_hash,
'historie' , $car_history,
'korrekt' , $car_correct,
'kilometer' , $car_km,
'brand' , $car_brand,
'model' , $car_model,
'post_nummer' , $user_zip,
'navn' , $user_name,
'telefon' , $user_phone,
'email' , $user_mail,
'datetime' , $user_datetime,
'customer_city' , $city,
'customer_country' , $country,
'customer_lat' , $lattitude,
'customer_lng' , $longitude
);

DataTables. How to access what is filtered and by what order in response?

I'm using DataTables in project not implemented by me, and I'm trying to figure out how to get filter and order data from Response.
In .php file that is defined in Ajax:
var table = $('#table').DataTable({
ajax: {
url: "../admin/ajax/product.php",
data: function (d) {
... I have access to $_GET variable with data about what is filtered and what order is in use (print_r):
Array
(
[draw] => 2
[columns] => Array
(
[0] => Array
(
[data] => 0
[name] =>
[searchable] => false
[orderable] => false
[search] => Array
(
[value] =>
[regex] => false
)
)
[1] => Array
(
[data] => 1
[name] =>
[searchable] => true
[orderable] => true
[search] => Array
(
[value] =>
[regex] => false
)
)
[5] => Array
(
[data] => 5
[name] =>
[searchable] => false
[orderable] => true
[search] => Array
(
[value] => 5
[regex] => false
)
)
)
[order] => Array
(
[0] => Array
(
[column] => 2
[dir] => asc
)
)
[start] => 0
[length] => 10
[search] => Array
(
[value] =>
[regex] => false
)
[method] => getList
)
Now I need these information (what is filtered and by what order) in response to do something with this data in next Request but this time without ajax and DataTable.
How to access what is filtered and by what order in response?

show X,Y Coordinate shapefile in google map

I wanna show this Shapefile data that extracted from SHP file in google map API :
DATA :Array
(
[Id] => 0
[area] => 164.914
[PARCID] =>
[deleted] => 0
)
SHAPE :Array
(
[xmin] => 539544.25
[ymin] => 3947728.5
[xmax] => 539559.4375
[ymax] => 3947745.75
[numparts] => 1
[numpoints] => 15
[parts] => Array
(
[0] => Array
(
[points] => Array
(
[0] => Array
(
[x] => 539546
[y] => 3947731.75
)
[1] => Array
(
[x] => 539544.25
[y] => 3947732
)
[2] => Array
(
[x] => 539545.5
[y] => 3947736.5
)
[3] => Array
(
[x] => 539546.375
[y] => 3947739.5
)
[4] => Array
(
[x] => 539546.8125
[y] => 3947741
)
[5] => Array
(
[x] => 539548.1875
[y] => 3947745.75
)
[6] => Array
(
[x] => 539556
[y] => 3947743
)
[7] => Array
(
[x] => 539556.1875
[y] => 3947743.5
)
[8] => Array
(
[x] => 539559.4375
[y] => 3947742.25
)
[9] => Array
(
[x] => 539557.8125
[y] => 3947737
)
[10] => Array
(
[x] => 539556.75
[y] => 3947733
)
[11] => Array
(
[x] => 539555.375
[y] => 3947728.5
)
[12] => Array
(
[x] => 539554.5
[y] => 3947728.75
)
[13] => Array
(
[x] => 539549.3125
[y] => 3947730.75
)
[14] => Array
(
[x] => 539546
[y] => 3947731.75
)
)
)
)
)
but when I check it get LATLNG coordinate, anyone can help to put these X,Y data on google map data !!!!
thank you
Sure what you want to use is JSON to parse it and send it to Google Maps. First you will need to format your numbers into actual latitude longitude coordinates. Here is how to use JSON to parse it: http://code.google.com/apis/maps/documentation/localsearch/jsondevguide.html
Alternately, I am not sure what you are trying to do with the data, but you could send it via a query string. (ex. http://maps.google.com/maps?q=52.961875,55.003296).

Kohana ORM Relationships

I'm trying to get to grips with the Kohana ORM but I'm a bit stuck.
I have created category and post models, with a relationship based on category_id.
I can fetch post and category models separately, however I cannot seem to fetch them using the relationship. For example:
// Get first category
$category = ORM::factory('category', 1);
foreach ($category->posts as $post)
{
echo $post->title;
}
The above just gives me a blank screen (I know I shouldn't be outputting anything in the controller, just trying to get it working first).
print_r($category);
Gives me this:
Model_Category Object ( [_has_many:protected] => Array ( [posts] => Array ( [model] => post [foreign_key] => category_id [through] => [far_key] => post_id ) ) [_has_one:protected] => Array ( ) [_belongs_to:protected] => Array ( ) [_load_with:protected] => Array ( ) [_validate:protected] => [_rules:protected] => Array ( ) [_callbacks:protected] => Array ( ) [_filters:protected] => Array ( ) [_labels:protected] => Array ( ) [_object:protected] => Array ( [id] => 1 [title] => [description] => ) [_changed:protected] => Array ( ) [_related:protected] => Array ( ) [_loaded:protected] => [_saved:protected] => 1 [_sorting:protected] => Array ( [id] => ASC ) [_foreign_key_suffix:protected] => _id [_object_name:protected] => category [_object_plural:protected] => categories [_table_name:protected] => categories [_table_columns:protected] => Array ( [id] => Array ( [type] => int [min] => 0 [max] => 65535 [column_name] => id [column_default] => [data_type] => smallint unsigned [is_nullable] => [ordinal_position] => 1 [display] => 6 [comment] => [extra] => auto_increment [key] => PRI [privileges] => select,insert,update,references ) [title] => Array ( [type] => string [character_maximum_length] => 65535 [column_name] => title [column_default] => [data_type] => text [is_nullable] => [ordinal_position] => 2 [collation_name] => latin1_swedish_ci [comment] => [extra] => [key] => [privileges] => select,insert,update,references ) [description] => Array ( [type] => string [character_maximum_length] => 65535 [column_name] => description [column_default] => [data_type] => text [is_nullable] => [ordinal_position] => 3 [collation_name] => latin1_swedish_ci [comment] => [extra] => [key] => [privileges] => select,insert,update,references ) ) [_ignored_columns:protected] => Array ( ) [_updated_column:protected] => [_created_column:protected] => [_primary_key:protected] => id [_primary_val:protected] => name [_table_names_plural:protected] => 1 [_reload_on_wakeup:protected] => 1 [_db:protected] => Database_MySQL Object ( [_connection_id:protected] => d6ad44aa068ae69071b9614f2a4a760bf55d9307 [_identifier:protected] => [last_query] => SHOW FULL COLUMNS FROMcategories` [_instance:protected] => default [_connection:protected] => Resource id #36 [_config:protected] => Array ( [type] => mysql [connection] => Array ( [hostname] => localhost [database] => cms_test_kohana [persistent] => ) [table_prefix] => [charset] => utf8 [caching] => [profiling] => 1 ) ) [_db_applied:protected] => Array ( ) [_db_pending:protected] => Array ( ) [_db_reset:protected] => 1 [_db_builder:protected] => [_with_applied:protected] => Array ( ) [_preload_data:protected] => Array ( ) )
Can anyone help?
Any advice appreciated.
Thanks.
Posts is a relationship, not a collection. Use find_all() or find() on a relationship to return a collection of records.
foreach ($category->posts->find_all() as $post) {
echo $post->title;
}
You can also apply various other methods to the relationship to filter the returned results using orderby, where, etc...