php / sql调用此:
<?php
// Filter our input.
$pID = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
if(!$pID) {
echo "No pID specified.";
exit;
}
$username = "##";
$password = "####";
$pdo = new PDO('mysql:host=localhost;dbname=###', $username, $password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $pdo->prepare('
SELECT name, lname, fname, picpath, email
FROM Department, Professor
WHERE pID = ?
;');
$sth->execute(array(
$pID
));
其他php代码:
if($sth->rowCount() > 0) {
$row = $sth->fetch(PDO::FETCH_ASSOC);
<div class='professor_pic'>
<img src='{$row['picpath']}' />
</div><!-- /professor_pic -->
<div class='professor_desc'>
<span class='one' style='float:left; padding:5px 0 0 5px;'><strong>Department:</strong> {$row['name']} </span><br>
} else {
echo "No results.";
}
unset($sth);
?>
为什么这两个字段'picpath'和'name'不被拉?它没有抛出任何错误。以上是两个数据库字段:
答案 0 :(得分:0)
我怀疑你的初始SQL查询有很多错误。
我建议您阅读MySQL JOIN。考虑到我理解该查询应该如何运行,请尝试:
SELECT d.name, p.lname, p.fname, p.picpath, p.email FROM Professor p JOIN Department d ON d.dID = p.dID WHERE p.pID = ?