我使用此代码从数据库中获取行。
// Prepare WC statement
$queryUP = $pdo->prepare("SELECT * FROM unitprices WHERE id_quot = :idQuotation");
// Execute Unit prices statement
$queryUP->execute(array(
'idQuotation' => $idQuotation
));
// How to check the results is empty or not ?
if (results) {
// foreach($queryUP as $rowup) {
//...
// }
} else {
// do another thing
}
在继续代码之前,我不知道如何检查查询中是否有某些结果?
答案 0 :(得分:2)
$queryUP = $pdo->prepare("SELECT * FROM unitprices WHERE id_quot = ?");
$queryUP->execute(array($idQuotation));
//here you go
$results = $queryUP->fetchAll();
if ($results) {
// foreach($results as $rowup) {
//...
// }
} else {
// do another thing
}
希望你在模板中做好准备,而不是如此处所示。
答案 1 :(得分:0)
如果您的记忆允许,您可以获取所有内容:
$queryUP = $pdo->prepare("SELECT * FROM unitprices WHERE id_quot = :idQuotation");
$queryUP->bindParam(':idQuotation', $idQuotation, PDO::PARAM_STR);
$queryUP->execute();
$result = $queryUP->fetchAll(PDO::FETCH_ASSOC);
if (count($result) > 0) {
} else {
}