How do i concatenate a number of SQL columns and store the result in a result column? I am presently testing it using the following code:
***TEST.PHP***
<?php
include 'core/init.php';
$result = mysql_query('SELECT concat(q1, q2) as result FROM assessment WHERE assessmentid = 32');
while ($row = mysql_fetch_assoc($result)){
echo $row['result'];
}
?>
In my assessment table, I have the following columns:
assessmentid | q1 | q2 | result
In q1, there is the value of 3 in q1, and 5 in q2 therefore 35 is being echo'ed. I'm unsure on how I can add this result to my database table.
assessmentid | q1 | q2 | result
UPDATE assessment set `result` = CONCAT(`q1`, `q2`) where condition
i don't think i fully understand you question.... if i didnt understand maybe you can explain better what you want?
$result = mysql_query('SELECT concat(q1, q2) as result FROM
assessment WHERE assessmentid = 32');
$q1=mysql_result($result,0,"q1");
$q2=mysql_result($result,0,"q2");
$concat = $q1 . $q2 ;
$query = "INSERT INTO assessment (result) VALUES
('$concat')";
$result = mysql_query($query) or die ("error");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.