Hi

I am trying to join 2 sentences together using php and mysql. How can i do so?

I am doing this as i need to add an update of a new remarks to the existing remarks.

For example,

$first = 'Hello';
$second = 'world';

To get the string 'Hello world', can i actually simply just add $first and $second ie:

$final = $first + $second ;
Thanks

use concatenation operator:
$final = $first . $second ;

Member Avatar for rajarajan2017

Logic:

Get the content from the databse and stored it in a variable
$content=sqlContent;
$updRmrks="This is extra text has to be palced";

$content = $content . $updRmrks;

update the record with usual update query and overwrite the contents.

Hope you understand the logic!

if you want to use two columns to concat into third column then you may use following query

update mytable set col1=concat(col2,col2) where col4='mycondition'

Thanks guys for the replies.

works fine. However i am trying to overwrite a content in one of the table. ie:

Case 1:
$first = 'NA';
$second = 'Hello world';
$final = $second;

Case 2:
$first = 'Hello';
$second = 'world';
$final = $first.$second ;


For 1st case, if $first = 'NA', then $final will be set to $second as i want to overwrite $first.
For the 2nd case, if $first != 'NA', then $final will be a combination of $first.$second

I tried to use if.. else statement to solve it but somehow i will still get $final = $first.$second as my result be it $first = 'NA' or 'first'.
below is my code:

if ($first != 'NA' || $first != 'Nil' ) 
{ 	$first = $first .",".$second; 
}
         else {
	$first  = $second; 
	         }

Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.