php – 如何在一行中显示SQL查询结果?

前端之家收集整理的这篇文章主要介绍了php – 如何在一行中显示SQL查询结果?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想出去试图让它发挥作用,我在这里,我有3张桌子.我认为向你展示表格是“tblhosting”,“tblhostingconfigoptions”和“tblcustomfieldsvalues”会更好.这可以在sqlFiddle设置中看到:http://sqlfiddle.com/#!9/6c153/1

我想要完成的是将它放在一行,见图:

下面是我的SQL查询

SELECT DISTINCT 
t1.domainstatus,t1.server,t1.dedicatedip,t1.packageid,t1.regdate,t1.nextduedate,t2.value,t2.fieldid,t3.configid,t3.qty
FROM tblhosting t1
INNER JOIN tblcustomfieldsvalues t2 
ON t2.relid = t1.id 
INNER JOIN tblhostingconfigoptions t3 
ON t3.relid = t1.id
WHERE t3.configid IN (126,127,128) AND t2.fieldid IN
(83,84,85,86,87,88,90,91,92,93,208) ORDER by t1.id -- I use to have GROUP by t1.id and get 1 line for the 126 but then 127 128 will not be produced.

我会隔离< td>只是问题,它都在这个PHP代码中:

$sql = MysqL_query($queryText);

while($row = MysqL_fetch_array($sql)) {

  $qty = $row['qty'];
  $configid = $row['configid'];

  echo '

….上面的想法是使$configid匹配126或127或128,并相应地输出行qty为4 0 0并且不输出3次“ded13526”并且输出4然后下一行0然后下一行0.

希望它有足够的解释,我不想发布整个代码混淆,很明显IN语句有80到93然后208,这个确切的条目只有93 ..

我只是不知道出了什么问题..

最佳答案
如果我正确理解您的问题,可以解决以下问题:

SELECT DISTINCT 
t1.domainstatus,(SELECT qty FROM tblhostingconfigoptions WHERE relid = t1.id AND configid = 126) AS qty126,(SELECT qty FROM tblhostingconfigoptions WHERE relid = t1.id AND configid = 127) AS qty127,(SELECT qty FROM tblhostingconfigoptions WHERE relid = t1.id AND configid = 128) AS qty128
FROM tblhosting t1
JOIN tblcustomfieldsvalues t2 ON t2.relid = t1.id 
WHERE t2.fieldid IN (83,208)
while($row = MysqL_fetch_array($sql)) {
  ...
  echo '
原文链接:https://www.f2er.com/mysql/433974.html

猜你在找的MySQL相关文章