<div class="nhplft">
<div class="view_item_title"><i><?= $users["First_name"]["First_name"]; ?> in MANHATTAN has (an)</i> <?= $item["Item"]["item"]; ?><br /></div>
that line of code is pulling the item name from the ITEMS table and the ITEM field... what can i do to display the user first_name from USERS table in the same database on this page http://whitelabel.neighborrow.com/app/items/view/2
Most likely you pull data in the standard CakePHP manner.
So, if your controller pulls data from the Users model:
$this->set( 'users', $this->User->find('first', ..other conditions..) );
Your view will output the first_name column from the database by doing:
<?php echo $users['User']['first_name']; ?>
If that doesn't make sense, I'd recommend you brush up on Cake (this is Cake-101).
From your view code I think you need to link your models together.
" $users["First_name"]["First_name"]; "
Is your Users table really called 'First_name' ?
Related
I have what is probably a very basic question. I have a column in my computer record with the id of the customer who owns the computer. I am trying to show their name in a table next to the computers' and found a temporary solution. I am using this in my view (which probably isn't proper MVC) and also makes the page take forever to load (I am showing 100 computers per page).
<td>
<?php
foreach ($customers as $customer):
if ($computer->cust_id == $customer->id) {
echo $this->Html->link(
$customer->first.' '.$customer->last,
['controller'=>'Customers', 'action'=>'view', $customer->id]
);
}
endforeach;
?>
</td>
I also tried to do $this->Customers->get($computer->cust_id) after loading the model in the Controller but it says I need a Customer Helper. What is the CakePHP method of taking care of this issue?
Thanks!
I used webpatser/laravel-countries
in my controlleer
$countries= DB::table('countries')->lists('name');
to select country list in my form i got all the country
{!! Form::select('country',$countries,null) !!}
in my schema now i have like this
$table->string('country');
i can select the country but when i submit country column blank. any idea ?
Edit 2:
Your insert need to look like this:
DB::table('users')->insert(
['country' => 'Canada']
);
https://laravel.com/docs/5.2/queries#inserts
Edit: if you want to submit the string of the country name then you need the string to be the key in your array. Like this:
$countries= DB::table('countries')->lists('name', 'name');
That's not typical use of a database relationship though. I'd expect the user table to have a country_id integer field that matches the id field in countries. That's what my original answer (below) covers.
Original:
You'll want the id in your $countries array. I bet right now your ids are off by one, starting at 0 instead of 1 like in your DB.
$countries= DB::table('countries')->lists('name', 'id');
There are different ways to save relations in laravel, but I actually prefer to skip that when possible and save directly to the country_id field.
{!! Form::select('country_id',$countries,null) !!}
But that depends on how your relationship is setup. And how you're saving. Show all the code!
I'm new to Yii2 but not to MVC (trying to move my focus from MS to Yii2). I've scaffolded up an app from my DB using gii. I have a table called track I have a table called music_category. There's a n:n relationship via a link table called track_has_music_category. My track model (as scaffolded by gii) has a function
public function getMusicCategories()
{
return $this->hasMany(MusicCategory::className(), ['id' => 'music_category_id'])->viaTable('track_has_music_category', ['track_id' => 'id']);
}
But that is for retrieving the categories that have been 'link'ed to this track. So I guess I need something like
<?= Html::activeDropDownList(theCategoryModel (syntax here??), 'id', ArrayHelper::map(theCategoryModel->findAll(),'id', ''description)) ?>
Well, something like that. I feel as though the online reference could do with a few worked examples.
Any help much appreciated.
Cheers
Mark
Let's say we want to attach some categories to a track model ($model):
echo Html::activeCheckboxList($model, 'musicCategories', ArrayHelper::map(MusicCategory::findAll(),'id', ''description))
We use activeCheckboxList here since it's a multiple relation.
Although you will need to add extra $model logic to save these relations.
Have a look at this How do I work with many-to-many relations in Yii2
my question is if is possible and how can i fill the description field on the payment form, whith a reference number from my slq database ?
Thank you.
You can try something like this query to define the description:
<?php $product = SELECT desc FROM table WHERE id = 'x'; ?>
And then use the $product variable to populate the value for "item_name" or whatever variable for the item description that matches the product you're using. I don't know what payment method you're using so I can't be more specific.
I am trying to display all users that have a meta data of with a specific value.
So in my case, I have a custom user meta data field called isblogger, with the options yes or no. So I would like to list users that have the isblogger value as yes.
Currently here is the code I have that is dispaying all users
global $wpdb;
$authors = $wpdb->get_results("SELECT
ID, user_nicename FROM $wpdb->users");
foreach($authors as $author) { ?>
list name etc...
Any help on this would be fantastic and much appreciated.
You have to add Where condition isblogger='yes'