divadiva Posted January 20, 2009 Share Posted January 20, 2009 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 Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/ Share on other sites More sharing options...
cytech Posted January 20, 2009 Share Posted January 20, 2009 Will it always be the first two characters in the externaltool_id? If so: $combined_id = substr($terms[$ic]['tool_id'], 0, 2).$i_row['tool_id']; echo $combined_id; Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741192 Share on other sites More sharing options...
divadiva Posted January 20, 2009 Author Share Posted January 20, 2009 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? Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741230 Share on other sites More sharing options...
cytech Posted January 20, 2009 Share Posted January 20, 2009 Hello, I'm not sure what its doing either hehe - I got it from your code Try this: <TD VALIGN="TOP"><?php substr($externaltool_id, 0, 2).$internaltool_id; ?></TD> I hope that clears it up a bit. Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741237 Share on other sites More sharing options...
phparray Posted January 20, 2009 Share Posted January 20, 2009 Here is a method using the mysql concat function instead of making php do it. Just change you select statement. Example: select concat(internaltool_id,externaltool_id) as ctool_id It will be put together for you in $i_row['ctool_id'] Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741250 Share on other sites More sharing options...
divadiva Posted January 20, 2009 Author Share Posted January 20, 2009 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. Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741349 Share on other sites More sharing options...
flyhoney Posted January 20, 2009 Share Posted January 20, 2009 Try this: SELECT CONCAT( LEFT(internaltool_id, 1), LEFT(externaltool_id, 1)) as ctool_id Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741354 Share on other sites More sharing options...
flyhoney Posted January 20, 2009 Share Posted January 20, 2009 Ooops. I mean this: SELECT CONCAT( LEFT(internaltool_id, 2), externaltool_id ) as ctool_id Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741356 Share on other sites More sharing options...
divadiva Posted January 20, 2009 Author Share Posted January 20, 2009 Hey Flyhoney Thanks.It worked. Link to comment https://forums.phpfreaks.com/topic/141609-solved-how-to-concatenate-database-field-values/#findComment-741381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.