你好這裏人是我的MySQL查詢哪一個獲取數據...難SQL查詢語法
$videofetch = $conn->prepare("select * from user_followers as uf join videos as v on uf.followed_id = v.publisher_id where uf.follower_id = ? order by video_id desc limit 5");
$videofetch->execute(array(@$_SESSION ["userid"]));
$vid = $videofetch->fetchALL(PDO::FETCH_ASSOC);
此代碼工作完美,但是當我試圖用AJAX來獲取更多的數據,我不能寫正確的sql查詢語法。
<?php
session_start();
if(isset($_POST["id"]) && !empty($_POST["id"])) {
include('connectdb.php');
$lastID = $_POST['id'];
$videofetch = $conn->prepare("select * from user_followers as uf join videos as v on uf.followed_id = v.publisher_id where uf.follower_id = ? order by video_id desc limit 5");
$videofetch->execute(array($_SESSION["userid"]));
$vid = $videofetch->fetchALL(PDO::FETCH_ASSOC);
...
我想補充WHERE video_id < ".$lastID."
..我tryed的情侶組合,但每次顯示語法錯誤。
注:
1 - 我從AJAX獲取數據到$lastID
;
2- $_SESSION ["userid"]
是積極的,不要擔心這個
3-SQL的錯誤是:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as v on uf.followed_id = v.publisher_id where uf.follower_id = '1' order by vid' at line 1 in C:\wamp64\www\hola.com\functions\getdatafoll.php on line 9
'video as v' =>'videos v' - 您使用'AS'來別名列而不是表格。 – Qirel
把你的表別名視頻 –
第一個查詢正在工作godd只是我想添加WHERE video_id <「。$ lastID。」'第二個查詢 –