Page 1 of 1

Array value concatenation?

Posted: Sun Feb 07, 2010 3:30 pm
by dillion
A client uses a custom-built software that manages their products catalog and this software generates a flat file which I can use to populate mySQL database for the online shop. Simple example of the flatfile:

Code: Select all

 
Title|iPod
Price|200
Stock|10
 
Title|iPod Blue
Price|200
Stock|10
etc...
 
I managed to write a script (using foreach, etc.) that adds the products to the database but I spotted a little problem. If a product has a rather long title or description, the format looks like this:

Code: Select all

 
Title|iPod the pink one with
Title|protective case and 
Title|personalised wallpaper
Price|300
Stock|20
 
Title|iPod
Price|200
Stock|10
 
So the title field in database contains only the value "personalised wallpaper" rather than the full title e.g. "iPod the pink one with protective case and personalised wallpaper".

Is there a PHP function or something that allows me to concat or merge values based on same key?

Many thanks in advance! :)

Re: Array value concatenation?

Posted: Mon Feb 08, 2010 11:04 am
by JakeJ
Query the database, throw it in to an array and then $concat = $row['field1'] + $row['fields2'];

The + operator is a concatenation operator in php. If you need a space in there, just do this: $concat = $row['field1'] + ' ' + $row['fields2'];

Re: Array value concatenation?

Posted: Mon Feb 08, 2010 2:40 pm
by tr0gd0rr
JakeJ wrote:The + operator is a concatenation operator in php.
No! Dot (".") is the string concatenation operator in PHP!

Not sure if you live in an alternate universe or if you have a bad case of the Mondays.

Re: Array value concatenation?

Posted: Mon Feb 08, 2010 3:43 pm
by JakeJ
I've completely lost my mind.

Re: Array value concatenation?

Posted: Tue Feb 09, 2010 1:32 pm
by tr0gd0rr
JakeJ wrote:I've completely lost my mind.
Darn! I was hoping you were in an alternate universe... sometimes I'd like to escape this one :D