我正在努力让这个工作,但却让我感到非常苦恼。我有三张表需要处理,它们分别是 "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 '<td id="sid">' . $row['value'] . '</td>';
echo '<td id="smip">' . $dedicatedIP . '</td>';
echo '<td id="10g">'; if ($configid == 126) { echo '4' } echo'</td>'; // the qty matching 126 should display there
echo '<td id="40g">'; if ($configid == 127) { echo '0'} echo'</td>'; // the qty matching 127 should display there
echo '<td id="100g">'; if ($configid == 128) { echo '0' } echo'</td>'; // the qty matching 128 should display there
上述想法是使
$configid
匹配126或127或128,并相应地将行qty
输出到字段中,其值为4 0 0,而不是3次输出“ded13526”,然后放置4、下一行放置0、再下一行放置0。希望有足够的解释,我不想发布整个代码以引起混淆,很明显
IN
语句有80到93然后208,而这个确切的条目只有93。我不知道哪里出了问题。