-1

我的数据库中有下表

表名是“product_question”

product_question_id int(11) No       
product_id  int(11) No       
user_name   varchar(100)    No       
user_email  varchar(200)    No       
envipor varchar(100)    No       
company_name    varchar(100)    No       
product_name    varchar(100)    No       
question    text    No       
product_image   varchar(500)    No       
date    timestamp   No  CURRENT_TIMESTAMP 

我有以下 sql 语句

我的 .php 页面中的语句 SQL 是

SELECT*
FROM product_question
WHERE company_name = $_SESSION['company_name']

但我希望将我的 .php 页面上的结果转换为以这种方式显示的简单语句

product: xbox 360
question: what is the price? - user_name: brian

product: ps3
question: has availability? - user_name: carlos

product: xbox 360
question: has games? - michael

product: ps3
question: what is the price? - user_name: luke

product:  smartphone
question : brings android? - selena

product: xbox 360
question: how many games? - user_name: daniel

我希望句子的结果以这种方式显示

产品:Xbox 360

question: what is the price? - user_name: brian
question: has games? - michael
question: how many games? - user_name: daniel

产品:ps3

question: has availability? - user_name: carlos
question: what is the price? - user_name: luke

产品:智能手机

question : brings android? - selena

但是,我不知道创建 sql 语句以获得所需的结果。

4

1 回答 1

0

如评论中所述,以您需要的格式从数据库中获取结果的方法将发出一个看起来像这样的查询。这是假设您使用的是 mysqli 的程序风格。

$sql = "select CONCATENATE('question: ', question, ' - ', user_name) as questionText ".
       "from product_question ".
       "WHERE company_name = '".mysqli_real_escape_string($dbConnection, $_SESSION['company_name'])."'";
于 2013-08-19T18:55:52.033 回答