-1

I have made " news & updates " simple script

my query is:

$query = mysql_query("SELECT * FROM a_commants WHERE postid='$postid' ORDER BY id DESC LIMIT 0,10");

it shows last comment

i want to make it show all comments or at least 10 comments

if i change it to:

$query = mysql_query("SELECT * FROM a_commants WHERE postid='$postid'");

it shows first comment only

idk whats wrong :(

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
Ism3lawy
  • 3
  • 3

1 Answers1

2

I think that the problem is in your php code, not MySQL. The query seems fine, as long as you have more than one comment, but it seems that you are not iterating through results, just printing the first row you get from db.

This should show last 10 comments:

$res = mysql_query("SELECT * FROM a_commants WHERE postid='$postid' ORDER BY id DESC LIMIT 0,10");
while($row = mysql_fetch_array($res)){ // iterate through results
    print_r($row); // print the row
}

And you should definitely switch to mysqli or PDO, and sanitize your inputs. The mysql_* functions are deprecated and going to be removed from PHP.

Community
  • 1
  • 1
Zagor23
  • 1,953
  • 12
  • 14