数据库中的两个表
table1  
id     name   
1       张  
2       王  
3       李  
4       赵  
table2  
id     option     value  
1        68         北京  
1        66         男  
1        10         2o岁  
1        16         上班  
1        15         大专  
2        68         上海  
2        66         女  
2        10         18岁  
2        11         豪宅  
我想取出的记录如下  1   张     北京   男  20岁  
2   王     上海   女  18岁 对应的sql 语句应该是select a.id,a.name,b1.value,b2.value,b3.value
from ((table1 a left join table2 b1 on a.id=b.id and b.option=68)
    left join table2 b2 on a.id=b.id and b.option=66)
    left join table2 b3 on a.id=b.id and b.option=10如何用php 把结果输出到网页?
1   张     北京   男  20岁  
2   王     上海   女  18岁 

解决方案 »

  1.   


    $jingthreads = ''; 
    $query = $db->query("SELECT * FROM {$tablepre}threads t LEFT JOIN {$tablepre}forums f ON f . fid =t . fid where digest ORDER BY `t` . `lastpost` DESC LIMIT 0, 5"); //替换为你的SQL文(把你的select a.id,a.name,b1.value,b2.value,b3.value
    from ((table1 a left join table2 b1 on a.id=b.id and b.option=68)
        left join table2 b2 on a.id=b.id and b.option=66)
        left join table2 b3 on a.id=b.id and b.option=10
    放到这里。)
     while($thread = $db->fetch_array($query))
     {
     $thread[subject] = cutstr($thread[subject], 26);
     $jingthreads.="<li><a href='../viewthread.php?tid=$thread[tid]' title='作者:$thread[author] 版块:$thread[name]'>$thread[subject] </a></li>" ; } //替换为你要的输出格式
      

  2.   


    感谢   这里 如何替换我懂得了 但是$thread[tid]  还有$thread[author]  是因为 tid 、author 只有一个
    而我需要的数据 却是多个的 b1.value,b2.value,b3.value  写 $thread[value] 是不对的吧
    应该怎样分别 调用 b1.value,b2.value,b3.value   的数据呢
     感谢