我的数据库中有下表
表名为"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语句来获得所需的结果。
如注释中所述,以您所需的格式从数据库中获取结果的方法将发出如下查询。这是假设您使用的是mysqli的过程风格。
$sql = "select CONCATENATE('question: ', question, ' - ', user_name) as questionText ".
"from product_question ".
"WHERE company_name = '".mysqli_real_escape_string($dbConnection, $_SESSION['company_name'])."'";