简体   繁体   English

如何连接和存储MYSQL列值?

[英]How to concatenate and store MYSQL column values?

How do i concatenate a number of SQL columns and store the result in a result column? 如何串联多个SQL列并将结果存储在结果列中? 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. 在q1中,q1中的值为3,而q2中的值为5,因此35被回显。 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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM