Getting nids using entityfieldquery - drupal-7

I want to get all the nids but I am unable to get them. Below is my snippet.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node');
$query->entityCondition('bundle', 'product');
$query->propertyCondition('status', 1);
$query->fieldCondition('field_product_sub_cat', 'tid',array($leaf_nodes));
$query->range(0, 10);
$result = $query->execute();
if (isset($result['node']))
{
$product_childnid = array_keys($result['node']);
}
Below is my result:UPDATED
Array
(
[node] => Array
(
[78] => stdClass Object
(
[nid] => 78
[vid] => 78
[type] => product
)
[80] => stdClass Object
(
[nid] => 80
[vid] => 80
[type] => product
)
[82] => stdClass Object
(
[nid] => 82
[vid] => 82
[type] => product
)
[84] => stdClass Object
(
[nid] => 84
[vid] => 84
[type] => product
)
[86] => stdClass Object
(
[nid] => 86
[vid] => 86
[type] => product
)
[88] => stdClass Object
(
[nid] => 88
[vid] => 88
[type] => product
)
[90] => stdClass Object
(
[nid] => 90
[vid] => 90
[type] => product
)
[92] => stdClass Object
(
[nid] => 92
[vid] => 92
[type] => product
)
[94] => stdClass Object
(
[nid] => 94
[vid] => 94
[type] => product
)
[100] => stdClass Object
(
[nid] => 100
[vid] => 100
[type] => product
)
)
)
then below code is providing me all the paths too,
$paths = array();
if (isset($result['node']))
{
foreach($result['node'] as $key => $node)
{
$paths[$node->nid] = drupal_get_path_alias("node/$node->nid");
}
}
now the next problem is how can I represent these paths in my anchor tag?Because they all are in an array.Below is my array structure of paths aliases:
Array
(
[78] => equivalent-fireman-glove-details
[80] => toughguard®-2
[82] => toughguard®-3
[84] => toughguard-®sizzler®
[86] => tough-guard-®
[88] => kevlar®-double-glove
[90] => nomex®-industrial-coverall
[92] => tough-guard®-clinker®-0
[94] => lab-coats-sa-nlc
)
and below is an array structure data to link with above paths:
Array
(
[0] => 71
[1] => 73
[2] => 81
[3] => 83
[4] => 85
[5] => 87
[6] => 89
[7] => 91
[8] => 93
)

Try this:
$query->fieldCondition('field_product_sub_cat', 'tid',array($leaf_nodes),'IN');
So that the query in compare value with array.

Related

how to merge them into one array in laravel

$category = Category::with('products')->where('seller_id','=',$request->
user('seller')->id)->get();
foreach($category as $index=>$opt){
foreach($opt->products as $key => $value)
{
print_r( array_column([$key => $value],'id'));
}
}
Array ( [0] => 33 ) Array ( [0] => 32 ) Array ( [0] => 36 ) Array ( [0] => 34 ) Array ( [0] => 35 )
i want this as my output
Array ( [0] => 33 ,[0] => 32 ,[0] => 36 , [0] => 34 , [0] => 35 )

How to print associative array in codeigniter

my controller is : **
public function getdatewiseOrder()
{
$cid = $this->input->post('cid');
$startdate = strtotime($this->input->post('start_date'));
$enddate = strtotime($this->input->post('end_date'));
$order = $this->model_reports->getdatewiseOrder($cid, $startdate, $enddate);
$x = 0;
foreach ($order as $key => $value) {
$item[$x] = $this->model_reports->getorderItem($value['id']);
$x = $x + 1;
}
$this->data['order'] = $order;
$this->data['item'] = $item;
$this->render_template('reports/leser_report', $this->data);
}
for check : after print_r of item variable i get data in this format:
Array (
[0] => Array (
[0] => Array (
[id] => 188
[order_id] => 93
[product_name] => 2
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 1
[qtypcs] => 2
[unit] =>
[rate] => 234
[amount] => 234.00
[tax_id] =>
[timestamp] => 2018-10-30 12:51:10
)
)
[1] => Array (
[0] => Array (
[id] => 191
[order_id] => 96
[product_name] => Small
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 5
[qtypcs] => 5
[unit] =>
[rate] => 100
[amount] => 500.00
[tax_id] =>
[timestamp] => 2018-11-15 09:49:41
)
[1] => Array (
[id] => 192
[order_id] => 96
[product_name] => Medium
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 5
[qtypcs] => 5
[unit] =>
[rate] => 90
[amount] => 450.00
[tax_id] =>
[timestamp] => 2018-11-15 09:49:43
)
)
[2] => Array (
[0] => Array (
[id] => 206
[order_id] => 105
[product_name] => Small
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 2
[qtypcs] => 50
[unit] =>
[rate] => 100
[amount] => 200.00
[tax_id] =>
[timestamp] => 2018-11-15 13:38:47
)
)
[3] => Array (
[0] => Array (
[id] => 207
[order_id] => 106
[product_name] => Medium
[barcode_nos] =>
[barcode_no] =>
[qtykg] => 50
[qtypcs] => 100
[unit] =>
[rate] => 15
[amount] => 750.00
[tax_id] =>
[timestamp] => 2018-11-15 13:40:12
)
)
)
I have two tables order and order_item and i am fetch data from both
for fetching data from order table i use
$order = $this->model_reports->getdatewiseOrder($cid, $startdate,
$enddate);
for fetching data from order_item i am using
$item[$x] = $this->model_reports->getorderItem($value['id']);
inside foreach loop
I want output in this format
enter image description here

display specific index multidimensional array

i have an multidimensional array like this, but i just only need some index to be displayed,
Array
Array
(
[0] => Array
(
[1] => 220
[38] => 200
[232] => 970
)
[1] => Array
(
[0] => 220
[2] => 190
[39] => 200
)
[2] => Array
(
[1] => 190
[3] => 40
[50] => 220
)
[3] => Array
(
[2] => 40
[4] => 200
[57] => 120
)
)
then i just want to display only index [1] and [3], so it would be like this
Array
(
[1] => Array
(
[0] => 220
[2] => 190
[39] => 200
)
[3] => Array
(
[2] => 40
[4] => 200
[57] => 120
)
)
i try using this code
$order = array(1,3);
uksort($graph, function($key1, $key2) use ($order) {
return (array_search($key1, $order) > array_search($key2, $order));
});
but still, its displayed the rest array that i dont need it that's key [0] and [2]
Like this:
foreach(array_keys($graph) as $key)
{
if($key == 0|| $key == 2)
{
unset($graph[$key]);
}
}
print_r
Array
(
[1] => Array
(
[0] => 220
[2] => 190
[39] => 200
)
[3] => Array
(
[2] => 40
[4] => 200
[57] => 120
)
)

How to Sum value according to other column value in cakephp

I'm cakephp learner and working on a project.
I have a problem. I did google but unable to find the right solution. I hope, I can find the solution here.
Here is My Code.
function getCompanySales(){
$model=ClassRegistry::init('Customer');
$modelcompany=ClassRegistry::init('Company');
$from = date("Y-m")."-01 00:00:00";
$days_in_month = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
$to = date("Y-m")."-".$days_in_month." 24:00:00";
$companyname=$modelcompany->find('all');
$companiessales=$model->find('all',array(
'conditions' => array(
"AND" =>array(
"Customer.created >=" => $from,
"Customer.created <=" => $to
)
),
'recursive'=>-1
)
);
return $companiessales;
} // Get Company list
and I'm getting result like
Array (
[0] => Array ( [Customer] => Array ( [gateway] => 10 [amount] => 349 ) )
[1] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 150 ) )
[2] => Array ( [Customer] => Array ( [gateway] => 13 [amount] => 349 ) )
[3] => Array ( [Customer] => Array ( [gateway] => 10 [amount] => 350 ) )
[4] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 100 ) )
[5] => Array ( [Customer] => Array ( [gateway] => 9 [amount] => 299 ) )
[6] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 249 ) )
[7] => Array ( [Customer] => Array ( [gateway] => 10 [amount] => 249 ) )
[8] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 299 ) )
[9] => Array ( [Customer] => Array ( [gateway] => 12 [amount] => 199 ) )
[10] => Array ( [Customer] => Array ( [gateway] => 7 [amount] => 150 ) ) )
But I want to Sum the Value with same gateway like
array(
[7] => 948 //sum of gateway 7
[9] => 299 //sum of gateway 9
[10] => 948 //sum of gateway 10
[12] => 199 //sum of gateway 12
[13] => 349 //sum of gateway 13
)
In another query =>
array(
[7] => company 1
[9] => company 2
[10] => company 3
[12] => company 4
[13] => company 5
)
I want a final result as
array(
[company1] => 948
[company1] => 299
[company1] => 948
[company1] => 199
[company1] => 349
)
Thanks for all your help. I'm sure I'll get the easy steps to resolve the issue.
Thanks for stackoverflow to give me ideas and find out an solutions.
I, first find the customer list by sum the amount and group by gateway by bellow code.
in the view use the custom helper to get the name by id. that's what , I was looking for.
$companiessales=$model->find('all',array(
'fields'=>array(
'SUM(amount) AS amount',
'gateway'
),
'group' => 'Customer.gateway',
'conditions' => array(
"AND" =>array(
"Customer.created >=" => $from,
"Customer.created <=" => $to
)
),
'recursive'=>-1
)
);
Here is the code to get the gateway name by id (which we are making primary id by grouping them)..
function getGatewayName($id){
$model=ClassRegistry::init('Gateway');
$companiess=$model->find('first',array(
'fields'=>array('fullname'),
'conditions'=>array(
'Gateway.id' => $id,
),
'recursive'=>-1
)
);
$name=$companiess['Gateway']['fullname'];
return $name;
} // Get Payment Gateway Name

print array multidimensional values

i I have a problem to print array .I received this array of web services by nusoap
How can I display the values ​​of this multidimensional array. I worked with foreach, I could not do it., Please explain with an example. Thanks
my array:
Array ( [Result] => Array ( [Root] => Array ( [row] => Array ( [0] => Array ( [!R] => 0 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 91 ) [1] => Array ( [!R] => 19 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 92 ) [2] => Array ( [!R] => 38 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] =>name2 [!C8] =>name2 93 ) [3] => Array ( [!R] => 57 [!C1] => 300064 [!C2] => name1 [!C3] => 1287744941 [!C4] => 798 [!C5] => 1338/06/29 [!C6] => [!C7] => name3 [!C8] => name3 ) ) ) ) )

Resources