I use Smarty v.1.6,
in php :
$groups = $user_groups['data'];
$user_groups['data'] derived from $user_groups = $facebook->api('/'.$fbuser.'/groups');
(I retrieve user facebook group data and it returns an array). Then I assign $groups in tpl file :
$template->assign("userGroupsData", $groups);
I want to print only the name of each group, so in tpl :
{foreach from=$userGroupsData item=member}
{$member->name}
{/foreach}
but the result shows nothing. {$member->name|#print_r} will produce :
11111111111 (as the number of my group)
What's wrong with my code? Please help..
Here is the array result of {$member|print_r} :
Array (
[name] => beasiswa dirmawa ugm
[unread] => 25
[bookmark_order] => 999999999
[id] => 148164981898119 ) 1
Array (
[name] => Diskusi Jurusan IKE
[unread] => 1
[bookmark_order] => 999999999
[id] => 131266600402713 ) 1
Array (
[name] => ILMU KOMPUTER - UGM
[unread] => 7
[bookmark_order] => 9
[id] => 392009304179631 ) 1
Array (
[name] => Facebook Developers
[unread] => 25
[bookmark_order] => 999999999
[id] => 146797922030397 ) 1
...etc
Any help would greatly appreciated, thank you.
If it's an array you should use the period symbol (in smarty 2 and up, at least):
{$member.name}
http://www.smarty.net/docsv2/en/language.variables.tpl#language.variables.assoc.arrays
but it may be different in the version you're using
Related
Someone who has made this change?
Today the BO product list show the end customer price excl and incl vat.
I want if possible to show our wholesale price and mour end customer price excl vat instead. This is probably a change in AdminProductController but I dont know how. I run PS 1.6.1.6
Regards
Anders Yuran
Open /controllers/admin/AdminProductsController.php from your PrestaShop root directory and in the __construct() function, you will see the following code:
$this->fields_list['price'] = array(
'title' => $this->l('Base price'),
'type' => 'price',
'align' => 'text-right',
'filter_key' => 'a!price'
);
This code is responsible for showing the price in products list, try replacing the code with the following:
$this->fields_list['price'] = array(
'title' => $this->l('WholeSale price'),
'type' => 'price',
'align' => 'text-right',
'filter_key' => 'a!wholesale_price'
);
Hope it helps.
Im new to PHP and I made this to display to my website what has been uploaded in the fdpp portal
<?php $resp = file_get_contents("http://fdpp.blgs.gov.ph/api/documents?source=datatable&sSearch=kalinga");
$clean = json_decode($resp);
print_r($clean); ?>
this is the result :
stdClass Object
(
[iTotalRecords] => 130035
[iTotalDisplayRecords] => 879
[sEcho] => 0
[aaData] => Array
(
[0] => stdClass Object
(
[lgu] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129293'>CAR<br/>Kalinga<br />Balbalan</a>
[document] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129293'>Local Disaster Risk Reduction and Management Fund Utilization (LDRRMF)</a>
[period] => Quarter 1 2014
[status] => Required • SUBMITTED
[desc] => The atng.
)
[1] => stdClass Object
(
[lgu] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129188'>CAR<br/>Kalinga<br />Balbalan</a>
[document] => <a href=' http://fdpp.blgs.gov.ph/documents/view/129188'>Manpower Complement</a>
[period] => Quarter 1 2014
[status] => Required • SUBMITTED
[desc] => The file ag.
)
what shall I add to my code to put this in a table with column name lgu, document, period? I tried reading foreach manual but I cant figure it out can someone help me?
I have to agree with PeeHaa (+1) with not enough information given, but I'm going to attempt to help you out.
The following assumptions were made:
You have a local MySQL DB named "testdb"
You have the PDO extension installed
In "testdb", you have a table named "test_table" with 4
columns (id, lgu, document, period)
First, you need to set the second parameter in json_decode to true to return an associative array rather than an object (PHP: json_decode).
So, based upon the limited information, here is a working version:
<?php
$resp = file_get_contents("http://fdpp.blgs.gov.ph/api/documents?source=datatable&sSearch=kalinga");
$clean = json_decode($resp,true);
// Open connection to your MySQL DB
$db = new PDO('mysql:host=localhost;dbname=testdb', 'username', 'password');
// Parse the now-associative array and insert into table
foreach($clean['aaData'] as $doc){
$stmt = $db->prepare("INSERT INTO test_table(lgu,document,period) VALUES(:lgu,:document,:period)");
$stmt->execute(array(':lgu' => $doc['lgu'], ':document' => $doc['document'], ':period' => $doc['period']));
}
?>
You should really provide some more information for a more exact answer.
But, this should set you in the right direction.
I am new to Rails and I am using Ruby version 1.9.3 and Rails version 3.0.0.
I want to print an array in Rails. How do I do that?
For example, we have to use print_r to print an array in PHP:
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
Output:
<pre>
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
</pre>
How do I print an array in Rails?
You can use inspect like:
#a = ['a', 'b']
p #a #['a', 'b']
Or:
p #a.inspect #"[\"a\", \"b\"]"
You need to use awesome_print gem.
require 'awesome_print'
hash = {:a=>1,:b=>2,:c => [1,2,3]}
ap hash
output:
{
:a => 1,
:b => 2,
:c => [
[0] 1,
[1] 2,
[2] 3
]
}
It depends on what you want to use the array for.
To blindly output an array in a view, which has to be in a view, you should use debug and inspect like this:
<%= #array.inspect() %>
<%= debug #array %>
However, if you want to iterate through an array, or do things like explode(), you'll be better suited using the Ruby array functions.
You've got a couple of options here. I'm assuming you're doing this in an ERB template.
This will convert the array to YAML and print it out surrounded in <pre> tags
<%= debug [1,2,3,4] %>
And this will print it out formatted in a readable Ruby syntax:
<pre><%= [1,2,3,4].inspect %></pre>
Check out "Debugging Rails Applications" for more info.
Having some real problems with this and hoping someone can help. Here's a reduced sample of the data I'm working with. So here $order_info is an array, inside that array theres another array called $items and within that there's multiple arrays which have the item ID as a name (very annoying!). What I'm trying to do is loop through the arrays within the $items array - the problem is I won't know their name. Is it possible to just loop through every array within an array (which is also within an array!)? It also needs to use smarty. I've tried various nested for loops but all have just come back with a blank page, suggesting an error.
{$order_info} Array (86)
order_id => "15"
items => Array (2)
4008222099 => Array (19)
item_id => "4008222099"
order_id => "15"
product_id => "836"
product_code => "B0001WS6L2"
price => "229.95"
amount => "1"
extra => Array (9)
step => "1"
product_options => Array (0)
unlimited_download => "N"
product => "LINGO TR-2203 Pacifica Talk Talking T..."
company_id => "0"
is_edp => "N"
edp_shipping => "N"
base_price => "229.95"
stored_price => "N"
product => "LINGO TR-2203 Pacifica Talk Talking T..."
deleted_product => ""
discount => "0"
company_id => "0"
base_price => "229.95"
original_price => "229.95"
cart_id => "4008222099"
tax_value => "0"
subtotal => "229.95"
display_subtotal => "229.95"
shipped_amount => "0"
shipment_amount => "1"
1157311813 => Array (19)
item_id => "1157311813"
order_id => "15"
product_id => "744"
product_code => "B00028DM96"
price => "119.99"
amount => "1"
extra => Array (9)
step => "1"
product_options => Array (0)
unlimited_download => "N"
product => "Sharp Electronics PW-E550 Electronic ..."
company_id => "0"
is_edp => "N"
edp_shipping => "N"
base_price => "119.99"
stored_price => "N"
product => "Sharp Electronics PW-E550 Electronic ..."
deleted_product => ""
discount => "0"
company_id => "0"
base_price => "119.99"
original_price => "119.99"
cart_id => "1157311813"
tax_value => "0"
subtotal => "119.99"
display_subtotal => "119.99"
shipped_amount => "0"
shipment_amount => "1"
The following solved it - should help if people need to do the same in the future:
{foreach from=$order_info.items item=foo}
{$foo.product_id}
{/foreach}
I have this find condition pulling from my model that currently looks like this.
#major_set = Interest.find(:all, :conditions => {:id => 1..21})
I'd like to add some more individual ids that I've just added which are like 120...130. I tried to do...
#major_set = Interest.find(:all, :conditions => {:id => 1..21, 120..130})
but got the error. " syntax error, unexpected '}', expecting tASSOC ...ns => {:id => 1..21, 122..130})"
How can I select multiple sets of id's as well as maybe some individual ids, ie ( :conditions => {:id => 1..21, 121..140, 144, 155 }??
You can convert the ranges to arrays and add them together. E.g.
#major_set = Interest.find(:all,
:conditions => {:id => (1..21).to_a + (120..130).to_a})
If you then want to add in individual ids then you can just add them to the array. E.g.
ids_to_find = (1..21).to_a + (120..140).to_a
ids_to_find << 144
ids_to_find << 145
#major_set = Interest.find(:all, :conditions => { :id => ids_to_find })
If you type {:id => 1..21, 122..130} inside irb you will get an error because it is not valid ruby syntax. This is interpreted as a hash where the first element is :id => 1..21 and the second is missing its key.
In order to make it a valid ruby expression, you would need to type:
{:id=>[1..21, 122..130]}
But I don't think that ActiveRecord will accept that syntax. So you may need to:
:conditions => "id BETWEEN 1 AND 21 OR id BETWEEN 122 AND 130"
This works in MySQL. I don't know if it will work in other databases.