Array value concatenation?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Array value concatenation?

Postby dillion » Sun Feb 07, 2010 4:30 pm

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:
Syntax: [ Download ] [ Hide ]
 
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:
Syntax: [ Download ] [ Hide ]
 
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! :)
dillion
Forum Commoner
 
Posts: 56
Joined: Thu Feb 15, 2007 9:32 am

Re: Array value concatenation?

Postby JakeJ » Mon Feb 08, 2010 12:04 pm

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'];
JakeJ
Forum Regular
 
Posts: 631
Joined: Thu Dec 10, 2009 7:27 pm

Re: Array value concatenation?

Postby tr0gd0rr » Mon Feb 08, 2010 3:40 pm

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.
667 - Neighbor of the Beast
User avatar
tr0gd0rr
Forum Contributor
 
Posts: 128
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Array value concatenation?

Postby JakeJ » Mon Feb 08, 2010 4:43 pm

I've completely lost my mind.
JakeJ
Forum Regular
 
Posts: 631
Joined: Thu Dec 10, 2009 7:27 pm

Re: Array value concatenation?

Postby tr0gd0rr » Tue Feb 09, 2010 2:32 pm

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
667 - Neighbor of the Beast
User avatar
tr0gd0rr
Forum Contributor
 
Posts: 128
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA


Return to PHP - Code

Who is online

Users browsing this forum: mecha_godzilla, Yahoo [Bot] and 1 guest