私は問題があり、見て、スタックオーバーフローサイトで多くのソリューションを見つけた しかし、私は自分のコードでそれを試しても動作していないようです。誰かが私のコードに何が間違っているかを知るのを助けることを望んでいました。どこで注文IDが動作しない
スタックオーバーフローのソリューション
mysql query with where and order by take long time
のいくつかの私は、次のようにしかし、応答は常に、ステータス= $状態データベースからレコードを選択しようとしています:
次のよう警告:/user/khloudamer/Documents/Websites/BusinessDoorFinal2/index.php on line 98のforeach()引数が無効です。
方法は次のとおりです。私は
(SELECT * FROM application where status = {$status} order by id desc limit 0,30')
(SELECT * FROM application where status = '$status' order by id desc limit 0,30')
AND
SELECT * FROM application where status = $status order by id desc limit 0,30
を試してみましたが、まだ何も動作
public static function readAlllisted($status){
try{
// = pending ORDER BY id DESC'
$db = Database::getInstance();
$dbh = $db->getConnection();
$results = $dbh->query('SELECT * FROM application where status = {$status} order by id desc limit 0,30');//select * from data where cat_id=12 order by id desc limit 0,30
return $results;
}catch(Exception $e){
return $e->getMessage();
}
1 id Primary int(11)
2 _customer_id char(8)
3 personal_id int(11)
4 emp_id int(11)
5 fin_id int(11)
6 status varchar(100)
私は方法を次のように私のテーブル構造がありますメソッドを呼び出す方法は次のとおりです。>>
あなたが間にそれを置く必要がありますので#statutがvarchar型であるため、 $app = Application::readAlllisted("pending");
foreach($app as $r){
echo $r['status'];
echo '<br/>';
echo $r['personal_id'];
echo '<br/>';
echo $r['emp_id'];
echo '<br/>';
}
?>
''* SELECT * FROM application where status = {$ status} order by id desc limit 0,30''は'' '(一重引用符)で囲まれています。 ''二重引用符で囲む – roullie
例外が発生していますが、返された文字列はチェックしません。if(is_array($ app)){foreach(...)} else {echo 'oops、error'。$ app;} ' –