0
我有多个奎雷斯从MySQL数据库检索数据(多表)不同的PHP变量,包括创建表if语句
SELECT description FROM table1 As descr WHERE type='MYTYPE'; //this shows description of each product type
SELECT count(id) FROM table2 As tp1 WHERE ACTIVE='Y' AND type=1"); //this is to count records that has this product type =1
SELECT count(id) FROM table2 As tp2 WHERE ACTIVE='Y' AND type=2");
SELECT count(id) FROM table2 As tp3 WHERE ACTIVE='Y' AND type=3");
SELECT count(id) FROM table2 As tp4 WHERE ACTIVE='Y' AND type=4");
什么我想拥有的是每种类型的描述表,与计数一起的活动产品有这种类型:如果计数为0,则忽略计数
这里是适度的尝试,工作,因为它有定义变量,如果陈述和逻辑不正确?
$tbl_header = '<tr>
<th width=220px align=left>Type description</th>
<th width=10px align=left>Active products of this type</th>
</tr>';
$tbl_data =
if (tp1>0) {
'<tr>
<td width=220px align=left><font color=#000000>'. {descr[0][0]}.'</td></font>
<td width=10px align=left><font color=#FF0000>.'$tp1.'</td></font>
</tr>';}
if (tp2>0) {
'<tr>
<td width=220px align=left><font color=#000000>'. {descr[1][0]}.'</td></font>
<td width=10px align=left><font color=#FF0000>.'$tp2.'</td></font>
</tr>';}
;
echo "<table> $tbl_header $tbl_data </table>";
虽然看起来有效,但不和我一起工作,如上面提到的,我想将其显示为$变量以后将pupulated在一个领域... – MikeDerik
任何其他的想法吗? – MikeDerik
看一看就是你的第二个片段。我假设信息存在,并且您的SQL数据被检索并正确存储。 –