0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I've got problem with SELECT SQL since ive included LIMIT, so my code looks like this:

$id = $_GET['id'];

$sql = "UPDATE rl_threads SET views = views + 1 WHERE id = '$id'";

$sql = mysql_query($sql);

//Pager

$ile = 10;

if(isset($_GET['page']))
{
  $strona = $_GET['page'];
}
else
{
  $strona = 1;
}

$strona = $strona - 1;

$offset = $strona * $ile;

//Koniec Pagera

$sql = "SELECT * FROM rl_posts LIMIT $od, 10 WHERE thread_id = '$id'";

$sql = mysql_query($sql);

until i havent add limit it worked properly but after the script says:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/radiolev/public_html/forum.php on line 194
Partnerzy

Can someone help me fixing this issue?

Community
  • 1
  • 1

2 Answers2

3

The correct SELECT syntax has LIMIT after the WHERE clause, like this:

$sql = "SELECT * FROM rl_posts WHERE thread_id = '$id' LIMIT $od, 10";

The error you're receiving, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource... is caused when the MySQL query fails. Updating to the above should fix the issue, assuming you have $od defined somewhere (if it's not defined, you will get see the same warning).

Side-note, not answer specific:
I would recommend upgrading to the MySQLi or PDO extensions. Both support prepared statements which can make your queries easier to read/manage and also offer additional security against SQL-Injection attacks.

newfurniturey
  • 37,556
  • 9
  • 94
  • 102
0
SELECT * FROM rl_posts WHERE thread_id = '$id' LIMIT $od, 10
mbinette
  • 5,094
  • 3
  • 24
  • 32
Sergio Toledo Piza
  • 793
  • 1
  • 6
  • 27