1

I have a this code:

$sql = "SELECT * FROM news order by id DESC LIMIT 10";
$data = array();
$query = mysql_query($sql);
if(!$query) {
    echo "Error: " . mysql_error();
    exit;
}
while($row = mysql_fetch_object($query)) {
    $data[] = $row;
}

return $data;

When I run code, result OK, But when I repair limit from 10 to limit 15 or more is error is unterminated string literal

$sql = "SELECT * FROM news order by id DESC LIMIT 15"; // limit 15, 20 or more
2
  • You're missing a ; at the end of the SQL statement. You have one at the end of the PHP statement but not at the end of the SQL statement. Commented Mar 27, 2012 at 4:01
  • 3
    @DavidSchwartz A ; isn't needed. mysql_query only accepts one query (making the semicolon not needed, or suggested). Commented Mar 27, 2012 at 4:04

2 Answers 2

2

Really? I don't mean to sound condescending but are you absolutely sure that you're not overwriting the " when you change that 10 to a 15?

Because there nothing in that code that indicates unbalanced quotes. Failing that, there may be a problem earlier on in the code (though, of course, we can't see it).

I would suggest you cut and paste the exact code that's causing the problems.

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

Comments

1

This the type of error you need to separate from your main code base. create a simple test php script that connects to the database and executes the query. does that work? if not, create a small sample database and test on that. if that fails, then post the create table statement along with insert statements. also post your code. odds are you're doing something else in the main code base that is causing the error.

if your sample code does work and your main codebase does, then you have to trace through your main code base and find out what you're doing wrong.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.