0
$cek=mysql_query('SELECT Header FROM CompletedHotelProjects LIMIT'.$count.', '.$count+2);

When I write this query, it fails. Can you help me, how can I write the right syntax?

Thanks...

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • What happens when you try to execute the query? Does it throw an error? What is the expected result? What are you getting instead? Your question lacks all these details. Please learn [how to ask a question](http://msmvps.com/blogs/jon_skeet/archive/2010/08/29/writing-the-perfect-question.aspx). :) – Amal Murali Sep 17 '13 at 12:21
  • 1
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Sep 17 '13 at 12:21
  • i think you shouldn't close the single quote after limit, in this case the limit is the end your query and the numbers are not counted as part of the query. – johnny Sep 17 '13 at 12:23
  • Every outdated mysql_ tutorial includes mysql_error(). Every question on StackOverflow regarding mysql_query() and an unknown error suggests mysql_error(). We don't need any more of these questions. – Mike B Sep 17 '13 at 12:23
  • WARNING: http://www.php.net/manual/en/function.mysql-query.php do you see the red rectangle? You should not use this function instead use PDO or MySQLi – Gianmarco Sep 17 '13 at 12:23
  • Why not go ORM with doctrine? – Mike de Klerk Sep 17 '13 at 12:25
  • at first, thank you for your beneficial answers all guys. Amal Murali, When I write this code, the query does not work. It gives error (!cek) – Hasan Sait Arslan Sep 17 '13 at 12:28

4 Answers4

1

Try this:

$cek = mysql_query(
   "SELECT Header FROM CompletedHotelProjects LIMIT ".$count.", ".($count+2).";"
       );
Minoru
  • 1,680
  • 3
  • 20
  • 44
  • 1
    Some programming languages are still a bit dumb. If you don't concatenate a `String` at the end, it may think that the `String` ends on the `", "`, giving you a syntax error. – Minoru Sep 17 '13 at 12:47
  • @HasanSaitArslan: You should accept the answer by clicking on the green-checkmark if it answers your question! :) – Amal Murali Sep 17 '13 at 13:25
0

Try this

$cek=mysql_query('SELECT `Header` FROM `CompletedHotelProjects` LIMIT '.$count.', '.$count+2);

EDIT: Maybe by adding the extra braces it will.

$cek=mysql_query('SELECT `Header` FROM `CompletedHotelProjects` LIMIT '.$count.', '.($count+2));

Always use `` signs to indicate a column or table and added a space between LIMIT and the first number.

Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
0

Try this :-

$new_count = $count+2;

$cek=mysql_query('SELECT Header FROM CompletedHotelProjects LIMIT $count,$new_count');
Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79
0

Can you please try with below query,

$countEnd = $count+2;
$cek=mysql_query('SELECT Header FROM CompletedHotelProjects LIMIT'.$count.', '.$countEnd);

i think this will help you to find a way.

Chandresh M
  • 3,808
  • 1
  • 24
  • 48