I have a user image upload (from Paid Memberships Pro Register Helper) which I want to place in a template file. If I do:
<?php
$key = 'logo';
$single = true;
$user_last = get_user_meta( $user_id, $key, $single );
if(!empty($user_last)){
var_dump($user_last); }
?>
I get:
array (size=7)
'original_filename' => string 'jp-logo.png' (length=11)
'filename' => string 'jp-logo.png' (length=11)
'fullpath' => string '/rel-local-path/jp-logo.png' (length=111)
'fullurl' => string '/full-local-path/jp-logo.png' (length=87)
'size' => int 20869
'previewpath' => string '/rel-thumbnail-path/jp-logo-200x168.png' (length=119)
'previewurl' => string 'full-thumbnail-path/jp-logo-200x168.png' (length=95)
from this, how do I echo the 'fullurl' value on the page?
Any help greatly appreciated!
Like this:
echo $user_last['fullurl'];
Related
how to fetch data from database in drupal7:
fields i have name:
subject:
email:
message:
give me the code for drupal 7 i want it in table form.
my insert code is this:
function form_example_form_submit($form, &$form_state) {
echo $name = $form_state['values']['textfield'];
echo $email = $form_state['values']['mail'];
echo $subject = $form_state['values']['subject'];
echo $message = $form_state['values']['message'];
echo $ip=ip_address();
echo $cb=$name;
//echo $timestamp = REQUEST_TIME;
echo $time=time();
$nid=db_insert('form') // Table name no longer needs {}
->fields(array(
'name' => $name,
'email' => $email,
'subject' => $subject,
'message' => $message,
'ip' => $ip,
'created_by' => $cb,
//'created_at' => $time,
))
->execute();
//print_r($nid);
drupal_set_message(t('The form has been submitted.'));
}
how can i fetch the data from database in drupal 7 in the form of table ,
give me the code .i m newbie in drupal 7 so its very difficult forme
Here is the snippet to fetch all content from "form" table with table format and pager. Also you can add condition which I have added in comment if required.
<?php
// Set header
$header = array(
array('data' => t('Name'), 'field' => 'name'),
array('data' => t('Email'), 'field' => 'email'),
array('data' => t('Subject'), 'field' => 'subject'),
array('data' => t('Message'), 'field' => 'message'),
);
//query to fetch all content
$query = db_select('form', 'f');
$query->fields('f');
//$query->condition('f.name', $search_name, '=') //if needed
$table_sort = $query->extend('TableSort') // Table sort extender
->orderByHeader($header); // Order by headers
$pager = $table_sort->extend('PagerDefault')
->limit(20); // Set page limit
$arr_result = $pager->execute();
$rows = array();
foreach($arr_result as $result) {
$rows[] = array(
$result->name,
$result->email,
$result->subject,
$result->message,
);
}
// Set empty output
$output = '';
if (!empty($rows)) {
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
/*'attributes' => array(
'id' => 'sort-table' // add if want to add sorting
) */
));
$output .= theme('pager');
}
else {
$output .= t("No results found.");
}
return $output;
?>
Let me know if any query/confusion occurs for the same.
I've got the following json object:
$dati = array(
"data" => array(
'address_complete'=>$data->results[0]->formatted_address,
'address_square'=>$data->results[0]->address_components[1]->long_name,
'location'=>$data->results[0]->address_components[2]->long_name,
'postal_code'=>$data->results[0]->address_components[7]->long_name,
'data_ora'=>$tmp_date
),
"str" => array ("n1"=>"fabio",
"n2"=>"marcolino",
"n3"=>"lauretta")
);
$p = json_encode($dati);
echo $p;
How can I enter the n1 element to show fabio as output?
$p.str.n1 doesn't work. How can I do this?
Besides, how can I show fabio,marcolino,lauretta using a for loop?
for ($i=1; $i<=3; $i++) {
$dati = array(
"data" => array(
'address_complete'=>$data->results[0]->formatted_address,
'address_square'=>$data->results[0]->address_components[1]->long_name,
'location'=>$data->results[0]->address_components[2]->long_name,
'postal_code'=>$data->results[0]->address_components[7]->long_name,
'data_ora'=>$tmp_date
),
"str" => array (
"n".$i=>"fabio",
"n".$i=>"marcolino",
"n".$i=>"lauretta")
);
//$p = json_encode($dati);
echo $dati[str]["n".$i];
}
How can I fix this code?
Finally I've got another question: if "str" => array ("n1"=>"fabio", "n2"=>"marcolino", "n3"=>"lauretta") are saved in a database and I want to get them from it, is correct to write in the following way?
"str" => array("n".$i=>"Ti sei incrociato con ".$array_db[username]),
and to call them with Ajax:
... success:function(msg){
if(msg){
$("#location").html(Object.keys(msg.str).map(x => msg.str[x]).join(", "));
}else{
$("#location").html('Not Available');
}
Besides How can I show "fabio","marcolino","lauretta" using a loop
for?
<?php
$dati = array(
"data" => array(
'address_complete'=>$data->results[0]->formatted_address,
'address_square'=>$data->results[0]->address_components[1]->long_name,
'location'=>$data->results[0]->address_components[2]->long_name,
'postal_code'=>$data->results[0]->address_components[7]->long_name,
'data_ora'=>$tmp_date
),
"str" => array ("n1"=>"fabio",
"n2"=>"marcolino",
"n3"=>"lauretta")
);
?>
<script type="text/javascript">
<?="var p = " . json_encode($dati) ?>
// print individual elements
for (i in p.str) {
console.log(p.str[i])
}
// print together
console.log(Object.keys(p.str).map(x => p.str[x]).join(", "))
</script>
I'm trying to create a function test that would be used for several buildings types but I can't get the variables to be passed into the View.
Controller code:
public function index($data = NULL){
$data1 = $this->test('hotel');
$data2 = $this->test('restaurant');
$data = array_merge($data1,$data2);
$this->load->view('templates/default',$data);
}
public function test($building_type){
$data[$building_type]['title'] = 'this is a title for '.$building_type;
for ($i=1;$i<=3;$i++) {
$data[$building_type][$i] = $building_type.' button';
}
$data['building_type_array'] = ['hotel', 'restaurant'];
return $data;
}
View code:
foreach ($building_type_array as $value) {
echo $value; // echoes 'hotel' and 'restaurant'
echo $value['title']; // throws 'Illegal string offset'
echo $value[3]; // echoes the 4th letter of 'hotEl' and 'resTaurant'
}
echo $building_type['title']; // Throws 'Undefined variable: building_type'
echo $hotel['title']; // echoes 'this is a title for hotel'
echo $hotel[3]; // echoes 'hotel button'
The first four echo are attempts that do not give the expected result. The last two echo of the View give the expected result but I would like to use a generic variable to avoid writing $hotel['title'], $restaurant['title'] ... for each building type.
Try something like this...
Controller:
public function index($data = NULL) {
$data['building_types']['hotel'] = $this->test('hotel');
$data['building_types']['restaurant'] = $this->test('restaurant');
$this->load->view('templates/default', $data);
}
View:
foreach ($building_types as $building) {
foreach ($building as $value) {
echo $value; // whatever
}
}
I don`t know if i understand you, but i understand that you have an array
like
$m_array = //come from model
array(
array(
'title' => 'title',
'1' => 'value1',
'2' => 'value2',
'3' => 'value3'
),
array(
'title' => 'title2',
'1' => 'value1-2',
'2' => 'value2-2',
'3' => 'value3-2'
),
array(
'title' => 'title3',
'1' => 'value1-3',
'2' => 'value2-3',
'3' => array('one' => 'v-one', 'two' => 'v-two')
),
//etc
);
in your view
foreach($m_array as $item => $value){
if( is_array($value)){
foreach($value as $row => $value2){
echo "<td>$item</td>";
echo "<td>$row</td>";
echo "<td>$value2</td>";
}
}
else{
echo "<td>$item</td>";
echo "<td>$value</td>";
echo "<td>-</td>";
}
}
Issue with afterFind().
Current code :
<?php
public function afterFind($results, $primary = false)
{
foreach ($results as $key => $val)
{
if (isset($val['User']['country_code']) && isset($val['User']['mobile']))
{
$results[$key]['User']['mobile'] = trim($val['User']['country_code']).trim($val['User']['mobile']);
}
}
return $results;
}
?>
It's working with $this->User->find(), but not working with other models.
I have 3 models. Room, Place and User.
<?php
$this->Place->bindModel(array('belongsTo' => array('User')));
$this->Room->bindModel(array('belongsTo' => array('Place')));
?>
When I try to find Room data :
<?php
$data = $this->Room->find('first');
array(
[Room] => array()
[Place] => array(
[User] => array(
[mobile] => /* here after find not working it should content country code + mobile */
)
)
)
?>
That might be problem with $reset while binding flyby. http://api.cakephp.org/2.1/source-class-Model.html#868-910
Please set $reset to false.
$this->Model->bindModel(array(...),false);
i am using this array for tag friends in a photo but no one is tagged , help me if i wrong.
$tags = array(
"tag_uid" => $id,
"tag_text" => $name,
"x" => 20,
"y" => 20
);
$facebook->api('/' . $new . '/tags?','post', array( $tags ));
this is because you are not doing the correct tags arrays. Try the following codes:
// Set tags limit
$f1 = $facebook->api('me/friends?limit=10');
// Get access token
$access_token = $facebook->getAccessToken();
// First post photo and then tag id
$post_photo = $facebook->api('/me/photos', 'POST', array(
'source' => '#' . $photo,
'message' => $message
)
);
// Creating Tags arrays for Tagging in the photo
foreach($f1['data'] as $fbu){
$tagx = array('tag_uid' => $fbu['id'],'x' => 30,'y' => 30 );
$ftags[] = $tagx;
}
// Tags generated now giving variable
$tagargs = array (
'tags' => json_encode($ftags),
'access_token' => $access_token,
);
// Posting the tags in photo
$result = $facebook->api('/' . $post_photo['id'] . '/tags', 'post', $tagargs);