I am getting a different result when I execute query in codeigniter active record form MyPhpAdmin
The following query run using MyPhpAdmin
SELECT * FROM (`ingredients`) LEFT JOIN `product_ingredients` ON `ingredients`.`ingredient_id` = `product_ingredients`.`ingredient_id` AND `product_id` = 46
gives the desired result which which includes the ingredient_id for both ingredient records that get returned.
Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => 2 [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )
But if I execute this query using Codeigniter Active record with the following code:
$this->db->select('*');
$this->db->join('product_ingredients', 'ingredients.ingredient_id = product_ingredients.ingredient_id AND `product_id` = 46', 'left');
$query = $this->db->get('ingredients');
Then the resulting array is missing the ingredient_id for the second ingredient result which is:
Array ( [0] => stdClass Object ( [ingredient_id] => 1 [display] => Sweet Almond Oil [slug] => sweet-almond-oil [title] => Sweet Almond Oil [description] => Sweet Almond Oil [featured_image_url] => [product_ingredient_id] => 10 [product_id] => 46 [display_position] => 2 [key_ingredient] => 0 ) [1] => stdClass Object ( [ingredient_id] => [display] => Shea Butter [slug] => shea-butter [title] => Shea Butter [description] => Shea Butter [featured_image_url] => [product_ingredient_id] => [product_id] => [display_position] => [key_ingredient] => ) )
Any help would be really appreciated...
Check it out
$this->db->select('i.*');
$this->db->from('ingredients i');
$this->db->join('product_ingredients pi', 'i.ingredient_id = pi.ingredient_id', 'left');
$this->db->where('pi.product_id',46);
$query = $this->db->get()->result_array();
Related
I have a Laravel collection with values, which I want to group by 'type' and sort by the biggest 'probability'. Here is how my collection looks like:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Array
(
[type] => correct-score
[name] => 1-1
[probability] => 10.599257670442
[probability_odd] => 10.142219704667
[odd] =>
[value_bet] => 0
[prognose_type_id] => 12
[value_bet_diff] => -10.142219704667
)
[1] => Array
(
[type] => 3-way
[name] => 1
[probability] => 52.459602877727
[probability_odd] => 2.0491958402842
[prognose_type_id] => 1
[odd] => 2.48
[value_bet_diff] => 0.4308041597158
)
[2] => Array
(
[type] => 3-way
[name] => 2
[probability] => 24.682032371379
[probability_odd] => 4.3553949845985
[prognose_type_id] => 1
[odd] => 2.66
[value_bet_diff] => -1.6953949845985
)
[3] => Array
(
[type] => 3-way
[name] => X
[probability] => 22.857984044926
[probability_odd] => 4.7029519221256
[prognose_type_id] => 1
[odd] => 3.7
[value_bet_diff] => -1.0029519221256
)
[4] => Array
(
[type] => double-chance
[name] => 1X
[probability] => 37.658793461327
[probability_odd] => 2.8545789739758
[prognose_type_id] => 4
[odd] => 1.49
[value_bet_diff] => -1.3645789739758
)
[5] => Array
(
[type] => double-chance
[name] => X2
[probability] => 23.770008208152
[probability_odd] => 4.5225058005294
[prognose_type_id] => 4
[odd] => 1.55
[value_bet_diff] => -2.9725058005294
)
[6] => Array
(
[type] => double-chance
[name] => 12
[probability] => 38.570817624553
[probability_odd] => 2.7870811826288
[prognose_type_id] => 4
[odd] => 1.29
[value_bet_diff] => -1.4970811826288
)
[7] => Array
(
[type] => both-to-score
[name] => yes
[probability] => 58.505776168275
[probability_odd] => 1.8374254140447
[prognose_type_id] => 8
[odd] =>
[value_bet_diff] => -1.8374254140447
)
I want to achieve as result something like that:
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => Array
(
[type] => correct-score
[name] => 1-1
[probability] => 10.599257670442
[probability_odd] => 10.142219704667
[odd] =>
[value_bet] => 0
[prognose_type_id] => 12
[value_bet_diff] => -10.142219704667
)
[1] => Array
(
[type] => 3-way
[name] => 1
[probability] => 52.459602877727
[probability_odd] => 2.0491958402842
[prognose_type_id] => 1
[odd] => 2.48
[value_bet_diff] => 0.4308041597158
)
[6] => Array
(
[type] => double-chance
[name] => 12
[probability] => 38.570817624553
[probability_odd] => 2.7870811826288
[prognose_type_id] => 4
[odd] => 1.29
[value_bet_diff] => -1.4970811826288
)
[7] => Array
(
[type] => both-to-score
[name] => yes
[probability] => 58.505776168275
[probability_odd] => 1.8374254140447
[prognose_type_id] => 8
[odd] =>
[value_bet_diff] => -1.8374254140447
)
Haven't been able to find similar solutions, so I finally decided to try here. Can you please help me?
Thanks in advance!
I think below can work;
$collection->sortByDesc('probability')->groupBy('type');
Sort by probability than group by type;
Probably better to do this in Eloquent, but as you have presented this as a collections problem;
assuming your collection is called $items
$sorted = $items->groupBy('type')
->map(function($group){
return $group->sortByDesc('probability')->take(1);
})
->flatten(1);
The most short:
$items = $collections
->sortByDesc('probability')
->unique('type');
I have a collection like the below. I need to fetch those users, whom does not uploaded documents. Now from the relationship, How can I fetch this?
[0] => Array
(
[id] => 2
[user_id] => 8
[referred_by] =>
........
[user_documents] =>
)
[1] => Array
(
[id] => 3
[user_id] => 9
[referred_by] =>
[reference_id] => NM1100008
.......
[user_documents] => Array
(
[id] => 1
[customer_id] => 3
[doc_type] => 1
[document] => N8xFORsPpkTayTQ9Ihyz0ly7QM62TJHxvHhSFQSN.png
[admin_comment] =>
[approve_status] => approve
[other_gov_id] =>
[doc_no] => 1
[created_at] => 2020-04-04 12:39:12
[updated_at] => 2020-04-06 13:57:01
[deleted_at] =>
)
)
I want to get rows only when user_documents is empty.. To get those users who does not uploaded documents to the system.
[user_documents] =>
Thanks in advance.
You can use laravel querying-relationship-absence
$users= User::doesntHave('user_documents')->get();
Depending on how you have setup your relations, something like this should work:
User::doesntHave('documents')->get();
I am having issue when i am getting google birthday calendar. I am getting wrong year in google birthday calendar.
Ex:
In my google contacts i am having contact name - Deepak whose birthday - 19/04/1990. So this contact birthday showing in the google birthday calendar. When i am fetching google birthday calendar i am getting date like 2017-04-19, 2018-04-19, 2019-04-19. How can i get contact exact birthday with year from google birthday calendar?
Response From Google Calendar API
[0] => Array
(
[kind] => calendar#event
[etag] => "3060534890000000"
[id] => 2017_BIRTHDAY_4a7a6b868dd53910
[status] => confirmed
[htmlLink] => https://www.google.com/calendar/event?eid=MjAxN19CSVJUSERBWV80YTdhNmI4NjhkZDUzOTEwICNjb250YWN0c0B2
[created] => 2018-06-29T10:17:25.000Z
[updated] => 2018-06-29T10:17:25.000Z
[summary] => Deepak's birthday
[description] => This is Deepak's birthday!
[creator] => Array
(
[email] => #contacts#group.v.calendar.google.com
[displayName] => Contacts
[self] => 1
)
[organizer] => Array
(
[email] => #contacts#group.v.calendar.google.com
[displayName] => Contacts
[self] => 1
)
[start] => Array
(
[date] => 2017-06-30
)
[end] => Array
(
[date] => 2017-07-01
)
[visibility] => public
[iCalUID] => 2017_BIRTHDAY_4a7a6b868dd53910#google.com
[sequence] => 0
[gadget] => Array
(
[iconLink] => https://calendar.google.com/googlecalendar/images/cake.gif
[preferences] => Array
(
[goo.contactsGivenName] => Deepak
[goo.contactsEventType] => BIRTHDAY
[goo.contactsFullName] => Deepak
[goo.isGPlusUser] => false
[goo.contactsContactId] => 4a7a6b868dd53910
[goo.contactsIsMyContact] => true
)
)
[reminders] => Array
(
[useDefault] => 1
)
)
[1] => Array
(
[kind] => calendar#event
[etag] => "3060534890000000"
[id] => 2018_BIRTHDAY_4a7a6b868dd53910
[status] => confirmed
[htmlLink] => https://www.google.com/calendar/event?eid=MjAxOF9CSVJUSERBWV80YTdhNmI4NjhkZDUzOTEwICNjb250YWN0c0B2
[created] => 2018-06-29T10:17:25.000Z
[updated] => 2018-06-29T10:17:25.000Z
[summary] => Deepak's birthday
[description] => This is Deepak's birthday!
[creator] => Array
(
[email] => #contacts#group.v.calendar.google.com
[displayName] => Contacts
[self] => 1
)
[organizer] => Array
(
[email] => #contacts#group.v.calendar.google.com
[displayName] => Contacts
[self] => 1
)
[start] => Array
(
[date] => 2018-06-30
)
[end] => Array
(
[date] => 2018-07-01
)
[visibility] => public
[iCalUID] => 2018_BIRTHDAY_4a7a6b868dd53910#google.com
[sequence] => 0
[gadget] => Array
(
[iconLink] => https://calendar.google.com/googlecalendar/images/cake.gif
[preferences] => Array
(
[goo.contactsGivenName] => Deepak
[goo.contactsEventType] => BIRTHDAY
[goo.contactsFullName] => Deepak
[goo.isGPlusUser] => false
[goo.contactsContactId] => 4a7a6b868dd53910
[goo.contactsIsMyContact] => true
)
)
[reminders] => Array
(
[useDefault] => 1
)
)
[2] => Array
(
[kind] => calendar#event
[etag] => "3060534890000000"
[id] => 2019_BIRTHDAY_4a7a6b868dd53910
[status] => confirmed
[htmlLink] => https://www.google.com/calendar/event?eid=MjAxOV9CSVJUSERBWV80YTdhNmI4NjhkZDUzOTEwICNjb250YWN0c0B2
[created] => 2018-06-29T10:17:25.000Z
[updated] => 2018-06-29T10:17:25.000Z
[summary] => Deepak's birthday
[description] => This is Deepak's birthday!
[creator] => Array
(
[email] => #contacts#group.v.calendar.google.com
[displayName] => Contacts
[self] => 1
)
[organizer] => Array
(
[email] => #contacts#group.v.calendar.google.com
[displayName] => Contacts
[self] => 1
)
[start] => Array
(
[date] => 2019-06-30
)
[end] => Array
(
[date] => 2019-07-01
)
[visibility] => public
[iCalUID] => 2019_BIRTHDAY_4a7a6b868dd53910#google.com
[sequence] => 0
[gadget] => Array
(
[iconLink] => https://calendar.google.com/googlecalendar/images/cake.gif
[preferences] => Array
(
[goo.contactsGivenName] => Deepak
[goo.contactsEventType] => BIRTHDAY
[goo.contactsFullName] => Deepak
[goo.isGPlusUser] => false
[goo.contactsContactId] => 4a7a6b868dd53910
[goo.contactsIsMyContact] => true
)
)
[reminders] => Array
(
[useDefault] => 1
)
)
Google calendar and google contacts are two different things. There is also a difference between a date of birth and a birthday. The former occurs only once the latter occurs once a year.
Ex: In my google contacts I am having contact name - Deepak whose birthday - 19/04/1990.
This is your entry in your address book for this user. Its the users date of birth.
So this contact birthday showing in the google birthday calendar. When i am fetching google birthday calendar i am getting date like 2017-04-19, 2018-04-19, 2019-04-19.
Google calendar birthday calendar gives you an event for each year for the users birthday that year. So that you dont forget to send flowers.
How can i get contact exact birthday with year from google birthday calendar?
You should be going though the google contacts api directly if you just want the data from your google contacts.
When iterating an array in Smarty I am getting results conflicting with a print_r() of the same array.
When doing a print_r() on the array I can see that there are 2 objects in the array and each object is unique. However, when I run a print_r() on each item of the array (via foreach loop) I seem to get the same results for each item.
Can anyone identify what I'm doing wrong?
See the below code examples and results.
Code:
{$fields.rgggo_spreadsheetcellmap_documents.value->beans|#print_r}
Ouput:
Array
(
[a852b076-a5cb-dda9-3868-52010d6957ab] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => a852b076-a5cb-dda9-3868-52010d6957ab
[name] =>
[date_entered] => 08/06/2013 09:52am
[date_modified] => 08/06/2013 02:16pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] => Test 2
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => document_type_text_c
[row] => 3
[col] => 1
.... a bunch more stuff here
)
[f038918d-a13d-69f0-3541-51fff82f0497] => RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
)
When I iterate the array...
{{foreach from=$fields.rgggo_spreadsheetcellmap_documents.value->beans key=k item=v}}
<pre>
{$v|#print_r}
</pre>
{{/foreach}}
I get these results:
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
RGGGO_SpreadsheetCellMap Object
(
[new_schema] => 1
[module_dir] => RGGGO_SpreadsheetCellMap
[object_name] => RGGGO_SpreadsheetCellMap
[table_name] => rgggo_spreadsheetcellmap
[importable] =>
[id] => f038918d-a13d-69f0-3541-51fff82f0497
[name] =>
[date_entered] => 08/05/2013 02:10pm
[date_modified] => 08/06/2013 02:17pm
[modified_user_id] => 1
[modified_by_name] => Sean
[created_by] => 1
[created_by_name] => Sean
[description] =>
[deleted] => 0
[created_by_link] =>
[modified_user_link] =>
[team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
[team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
[team_count] =>
[team_name] => Development
[team_link] =>
[team_count_link] =>
[teams] =>
[assigned_user_id] =>
[assigned_user_name] =>
[assigned_user_link] =>
[field] => description
[row] => 2
[col] => 1
.... a bunch more stuff here
)
I found the answer in another stackoverflow question. The issue is double vs single curly brackets and their use in SugarCRM.
Is there a difference between using a single vs. double brace (delimiters) in SugarCRM Smarty tpls command construct?
I have enterprise magento 1.10 and I need to add custom field to solr index in order to to have better search results. This custom field should contain category names for indexed product.
I need to know which part of magento I need to amend. I modified method Enterprise_Search_Model_Resource_Index::_getCatalogCategoryData which actualy produces some category related data but my new field doesnt appear in message to sorl.
Have I miss something?
Also I have some notes here, maybe it would someone help http://docs.nostresscommerce.com:8090/pages/viewpage.action?pageId=2490371
My output of rewrited Enterprise_Search_Model_Resource_Index::_getCatalogCategoryData, and I need category_name_level_* in solr.
[result] => Array
(
[12227] => Array
(
[#categories] => Array
(
[0] => 2
[3] => 3235
[7] => 2765
[10] => 6672
)
[#show_in_categories] => Array
(
[1] => 6671
[2] => 6670
[4] => 3224
[5] => 3199
[6] => 3191
[8] => 2761
[9] => 2760
)
[#position_category_2] => 1
[#position_category_6671] => 120000
[#position_category_6670] => 120000
[#position_category_3235] => 0
[#position_category_3224] => 150000
[#position_category_3199] => 150000
[#position_category_3191] => 120000
[#position_category_2765] => 1
[#position_category_2761] => 250001
[#position_category_2760] => 250001
[#position_category_6672] => 0
[#visibility] => 4
[#category_name_level_1] => Array
(
[0] => BCC Root Category
)
[#category_name_level_4] => Array
(
[0] => Huishouden
[1] => Top wasmachines
[2] => Accessoires wasmachine
)
[#category_name_level_3] => Array
(
[0] => Beste Koop Shop
[1] => Top
[2] => Wasmachine
)
[#category_name_level_2] => Array
(
[0] => Acties
[1] => Speciale informatie pagina's
[2] => Huishouden
)
[#category_name_level_5] => Array
(
[0] => Wasmachines
)
)
)
Thanks a lot,
Jaro.
I found a solution
class Xyz_Solrsearch_Model_Resource_Engine extends Enterprise_Search_Model_Resource_Engine {
public function __construct()
{
$this->_advancedDynamicIndexFields[] = '#category_name_level_';
parent::__construct();
}
}