-2

I have a code like this but it gives me error

 include_once 'wp-config.php';
    $number = 14 ;
    $result = mysql_query ("SELECT * FROM 'wp_posts' WHERE post_status='publish' ORDER BY ID DESC LIMIT $number 14 ); 
    while ($row = mysql_fetch_array($result)) 
  {
 $id = $row["ID"];
 $title = $row["post_title"];
 $content = $row["post_content"];

My blog is wp so any clue to slove this

Thank you

Ray
  • 40,256
  • 21
  • 101
  • 138
kamall
  • 1
  • 3

1 Answers1

1

You're missing the end double quote in your MYSQL query. Should be :

    $result = mysql_query ("SELECT * FROM 'wp_posts' WHERE post_status='publish' ORDER BY ID DESC LIMIT $number 14 "); 

However, this is still going to have another bug as LIMIT $number 14 is garbage.

  • Do you want to limit by 14 or $number?
  • is $number an offset? if so you'd want LIMIT $number, 14

I'm guessing by the rest of your code you just want to limit by number and the addition of 14 to the queryis a mistake. So use:

$result = mysql_query ("SELECT * FROM 'wp_posts' WHERE post_status='publish' ORDER BY ID DESC LIMIT $number "); 
Ray
  • 40,256
  • 21
  • 101
  • 138
  • $result = mysql_query ("SELECT * FROM 'wp_posts' WHERE post_status='publish' ORDER BY ID DESC LIMIT $number "); this but error is now Warning: mysql_query(): Access denied for user 'lekalic'@'localhost' (using password: NO) in & Warning: mysql_query(): A link to the server could not be established & Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in what to do now? any solutions – kamall Jun 01 '15 at 18:26
  • Now the code is syntactically correct, but you've got a credential issue with your DB connection. You should created another post asking about help resolving this. – Ray Jun 01 '15 at 18:49
  • I try to creat another post but i cant creat new for several days! I dont know how to slove this cause site is fine and only get topic is not working any help thank you! – kamall Jun 01 '15 at 18:54