views:

70

answers:

4

I would like to string together database values into a string. Something like $a "text" $b. And then use the entire string as a variable, let's say $c.

Is it better to do this at the database level? Will php use lots of resources to do this?

A: 

No, either database or php won't notice this operation.
Better to do in php as it would be a lot readable.

Col. Shrapnel
+4  A: 

Depends on the database, in mysql you can use the function CONCAT

For example, UPDATE users SET NAME=CONCAT('asd', 'asdfac') WHERE id=2;

Pran
A: 

perfectly acceptable - calculated or derived field in mysql for example

 select
  c.firstname,
  c.lastname,
  concat(c.firstname, ' ', c.lastname) as fullname
 from
  customer c
 where
  c.cust_id = 1;
f00
The php concat fn works nicely for me. Thanks for seeding the idea. <?php $str1 = 'This '; $str2 = 'is a '; $str3 = 'test string'; $full = $str1.$str2.$str3; echo $full; ?>
ggg
A: 

Are you wanting to save this longer string in the DB, or use it once removed (and show it as HTML or something?)

(can't comment, not enough rep!)

Bill X