0

I have 2 tables

1 table = files

 code | title 

luLidwhSl8hmN0T6RsLaDmxAB09UZcX |This is Rar title

4Xwvm1C3yTQJK7CnmxorUDI7sNSvcBK |This is JPG title

...

2 table = hits

 page_name | hits 

download.php?code=luLidwhSl8hmN0T6RsLaDmxAB09UZcX |102

download.php?code=4Xwvm1C3yTQJK7CnmxorUDI7sNSvcBK |87

...

My Query is :

 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>'; } 

I get this error

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Edu\filesupload\index.php on line 104 

Where is the problem?

2 Answers 2

1

Change this:

$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");

To this:

$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());

Then that should tell you what the error is, because if it was fine, it wouldn't be returning false.

Sign up to request clarification or add additional context in comments.

2 Comments

My error is :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.page_name, t2.hits FROM files t1 INNER JOIN hits t2 ON t1.code= RIGHT(t2.page_n' at line 1
That is the answer :$query = mysql_query("SELECT t1.code, t1.title, RIGHT(t2.page_name, 31), 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");
1

Try with this query:

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 

1 Comment

Some error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.page_name, t2.hits FROM files t1 INNER JOIN hits t2 ON t1.code= RIGHT(t2.page_n' at line 1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.