Welcome Guest, Not a member yet? Register   Sign In
'fullname' => $this->input->post('firstname') + ('lastname')
#1

[eluser]codedoode[/eluser]
I'm trying to do a basic CRUD app, and my code is listed below...

function create()
{
$data = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'fullname' => $this->input->post('firstname') + ('lastname'),
'company' => $this->input->post('company'),
'title' => $this->input->post('title'),
'address' => $this->input->post('address'),
'address2' => $this->input->post('address2'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'zip' => $this->input->post('zip'),
'office' => $this->input->post('office'),
'mobile' => $this->input->post('mobile'),
'fax' => $this->input->post('fax'),
'email' => $this->input->post('email'),
'comments' => $this->input->post('comments')
);

Why doesn't this work 'fullname' => $this->input->post('firstname') + ('lastname'), ??? what am I doing wrong?
#2

[eluser]danmontgomery[/eluser]
Code:
'fullname' => $this->input->post('firstname') . ' ' . $this->input->post('lastname'),
#3

[eluser]nelson.wells[/eluser]
+ is not the concatenation operator, . is. You would want to do this

Code:
'fullname' => $this->input->post('firstname') . " " . $this->input->post('lastname')

And this is why I believe one should know PHP before they try CI. It's good to use a framework, but not until you know how to use the language.
#4

[eluser]Twisted1919[/eluser]
Even if + would be a concatenation operator, wouldn't make sense to do like he did .
#5

[eluser]richthegeek[/eluser]
Ignoring the syntax error, why are you storing fullname, forename, and surname verbosely? Data redundancy should be avoided at all costs and you can infer fullname from fore/surname (concat) or vice versa (split).

You should keep data stored in only one place per item of data. The reasons are fairly simple:
1. Database size is reduced
2. Database updates and deletions are made much simpler, having only to change/delete one location.
3. Database indexing/searching is simplified, as you only have to index one location.

Your decision on how to store the name should be based on how you intend to use it in the end. Mostly you'll want to store it as the forename/surname split, as concatenation is a much "cheaper" operation than a split. However, if you only ever intend to *search* for and mostly only display the customer's name as it's full incarnation, then storing it in one field can simplify.
#6

[eluser]OliverHR[/eluser]
I agree with richgeek, why store data twice??
#7

[eluser]Matthieu Fauveau[/eluser]
Especially when MySQL as a CONCAT function...




Theme © iAndrew 2016 - Forum software by © MyBB