When I try to sort the values in descending order, I get an error:
Fatal error: Call to a member function prepare () on a non-object in /storage/sdcard0/www/shop/functions/functions_article.php on line 97
When sorting by ASC it works fine
Here is the request code:
function article_get_articles($date){ global $pdo; $articles = ""; $stmt = $pdo -> prepare('(SELECT id FROM articles WHERE article_status=1) ORDER BY id DESC'); $stmt->execute(); foreach($stmt as $row) { $articles .= article_get_homeblock($row['id']); } return $articles; $pdo = null; } Addition:
Connection:
$host = "localhost"; $db = "db"; $charset = "utf8"; $user = "user"; $pass = ""; $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $pdo = new PDO($dsn, $user, $pass, $opt); Working f-tion:
function article_get_author($data) { global $pdo; $stmt = $pdo -> prepare('SELECT article_author FROM articles WHERE id=? LIMIT 1'); $stmt->execute((is_array($data)?$data:[$data])); foreach ($stmt as $row) { return $row['article_author']; } }
ASCinstead ofDESCand everything works out as it should .... this is nonsense ........ and yes you have a bracket before theSELECTand after the status .. why are they? Probably an error in them .......... and why useprepareif no parameter is substituted? - Alexey Shimansky$pdoexists at all? Is there a connection? - Alexey Shimansky