Jump to content

[SOLVED] How to concatenate database field values?


divadiva

Recommended Posts

Experts,

 

I have two fields in database .One is internaltool_id(IN NUMBERS) .Other is externaltool_id(Characters).

 

internaltool_id =11234

externaltool_id=AABC21

 

 

In the web page .I want to see tool_id as  = AA11234.(Combaination of internaltool_id and externaltool_id)

 

How can  I concatenate teh internal and external tool_id and show in the front end?

 

 

<TH><NOBR>Tool</NOBR></TH> 
$terms[$ic]['tool_id'] = $i_row['tool_id'];// How to do concatenation  over here?

 

 

Best Regards,

Diva

THANKS FOR REPLYING.

But I am  trying to understand your code.

 

<TD VALIGN="TOP"><% substr($terms[$ic]['tool_id'], 0, 2).$i_row['internaltool_id']; %></TD>
//Is it adding the tool_id and internal_id?I mean what is $terms[$ic] doing?

 

 

 

Experts ,

 

Thanks for replying.

 

 

This worked .

Here is a method using the mysql concat function instead of making php do it. Just change you select statement.

 

Example:

[select]select concat(internaltool_id,externaltool_id) as ctool_id

 

It will be put together for you in $i_row['ctool_id']

 

 

 

But doing concat is giving me a full string form both the database fields .Whereas I want first 2 alphabet from the first field and second full field.

 

inexternaltool_id =12345
externaltool_id =AABBC
Currently I get 12345AABBC.but I want 

ctoolid as 12AABBC .

Here is  my code 

$ic = 0 ;
$terms = array() ;
$string = "SELECT *,concat(inventory.tool_id, inventory.internaltool_id) as ctool_id FROM `quotes_items`LEFT OUTER JOIN `inventory` ON quotes_items.inventory_id = inventory.inventory_id  WHERE quote_id = '$show'";
<TH><NOBR>Tool</NOBR></TH> 
$terms[$ic]['tool_id'] = $i_row['ctool_id'];

 

 

Any suggestions will be appreciated.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.