두 개의 명령문을 실행하고 while 루프 내에서 결과를 인쇄하고 싶습니다. 각 명령.은 두 개의 다른 테이블에서 데이터를 선택합니다.PHP 다중 준비 문
나는 이것을 접근하는 가장 좋은 방법이 확실치 않습니다.
내 코드는 다음과 같습니다.
$conn = new mysqli('localhost', 'user', 'password', 'db');
if ($conn->connect_errno > 0) {
die('Unable to connect to database [' . $conn->connect_error . ']');
}
$curDate = date("Y-m-d");
//first stmt
$stmt = $conn->prepare("SELECT start, status FROM log WHERE start >= ?");
$stmt->bind_param('s', $curDate);
$stmt->execute();
$stmt->bind_result($start, $status);
$stmt->close();
//second stmt
$stmt = $conn->prepare("SELECT time FROM params");
$stmt->bind_result($time);
$stmt->execute();
$stmt->close();
/* fetch values and echo for testing */
while ($stmt->fetch()) {
echo $start;
echo $status;
echo $time;
}
도움을 주시면 감사하겠습니다.
하나 개 쿼리를 가져올 수없는 이유라도? – Styphon
두 개의 쿼리 사이에 관계가 있어야한다고 가정합니다. 그렇지 않으면 동일한 루프에서 루프를 반복해도 상관 없습니다. Styphon이 말한 것처럼 하나의 쿼리에서 필요한 열을 선택하면 두 테이블을 결합 할 수 없습니다. – Ozzy
@typhon 어떻게해야하는지 잘 모르겠습니다./ –