![](/img/trans.png)
[英]mysql: get data from two tables depends on id of the first table and the result in json
[英]mysql 2 table, get result from 2 tables
我有2張桌子
1表=文件
code | title
luLidwhSl8hmN0T6RsLaDmxAB09UZcX |這是Rar冠軍
4Xwvm1C3yTQJK7CnmxorUDI7sNSvcBK |這是JPG標題
...
2 table =命中
page_name | hits
download.php?code = luLidwhSl8hmN0T6RsLaDmxAB09UZcX | 102
download.php?code = 4Xwvm1C3yTQJK7CnmxorUDI7sNSvcBK | 87
...
我的查詢是:
include('db.inc.php');
$query = mysql_query("SELECT t1.code, t1.title, RIGHT(t2.page_name, 31) as t2.page_name, t2.hits FROM files t1 INNER JOIN hits t2 ON t1.code= RIGHT(t2.page_name, 31) as t2.page_name ORDER by t2.hits DESC LIMIT 1, 7");
while ($result = mysql_fetch_assoc($query)) {
echo ' <div id="linkstyle"><strong><a href="http://localhost/edu/filesupload/download.php?code='. $result['t1.code'] . ' ">' , $result['t1.title'] , '</a></strong><br></div>';
}
我收到這個錯誤
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Edu\filesupload\index.php on line 104
問題出在哪兒?
改變這個:
$query = mysql_query("SELECT t1.code, t1.title, RIGHT(t2.page_name, 31) as t2.page_name, t2.hits FROM files t1 INNER JOIN hits t2 ON t1.code= RIGHT(t2.page_name, 31) as t2.page_name ORDER by t2.hits DESC LIMIT 1, 7");
對此:
$query = mysql_query("SELECT t1.code, t1.title, RIGHT(t2.page_name, 31) as t2.page_name, t2.hits FROM files t1 INNER JOIN hits t2 ON t1.code= RIGHT(t2.page_name, 31) as t2.page_name ORDER by t2.hits DESC LIMIT 1, 7") or die(mysql_error());
然后,這應該告訴你錯誤是什么,因為如果它沒有問題,它將不會返回false。
嘗試使用此查詢:
SELECT t1.code, t1.title, RIGHT(t2.page_name, 31) as page_name, t2.hits FROM files t1 INNER JOIN hits t2 ON t1.code= RIGHT(t2.page_name, 31) ORDER by t2.hits DESC LIMIT 1, 7
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.