//Table One {news}
Id1 | subject1 | url1 | source1
//Table Two {blog_news}
order_id | type | id1 | id
//Table Three {blog}
id | name | subject | url
//SQL query
SELCET nf.*, fnb.*, b.id, b.name, b.subject, b.url FROM news AS nf JOIN blog_news AS fnb ON nf.id1=fnb.id1 JOIN blog AS b ON fnb.id=b.id//Display Code
if(($i = 0; $i <= 5; ++$i)&&(fnb.type' ==1)){
//Order the result by 'order_id'
//Table Display Code
<table>
<tr>
<td width='250px' valign='middle' align='left'>
<font size='-2'>
<a herf='” . $_GET['b.url'] . “'>
<b>” . $_GET ['b.subject'] . “</b>
</a>
</font>
</td>
<td width='100px' valign='middle' align='right'>
<font size='-2'>
<a herf='” . $_GET['b.url'] . “'>
<b>” . $_GET ['b.name'] . “</b>
</a>
</font>
</td>
</tr>
</table>
}endif我正在尝试完成的是将三个数据库表连接在一起,并使用类似于{//display}代码部分的代码在两个区域中显示结果。
我试过很多不同的方法来完成这项任务。
我尝试在php中使用while循环来显示结果,但在while循环开始之前我收到了一个mysql_fetch_error()。我的目标也是让每个表在DESC顺序中按order_id排序。
发布于 2013-03-17 06:53:08
在MySQL中组织数据要容易得多。
试试这个:
SELECT nf.*, fnb.*, b.id, b.name, b.subject, b.url
FROM news nf
JOIN blog_news fnb ON nf.id1 = fnb.id1
JOIN blog b ON fnb.id = b.id
WHERE fnb.type = 1
ORDER BY fnb.order_id DESC
LIMIT 5看看MySQL的ORDER BY是如何工作的。
如果你不知道如何在php中使用MySQL,在你最喜欢的搜索引擎上快速搜索"MySQL和php教程“应该会有所帮助。
https://stackoverflow.com/questions/15455631
复制相似问题