Why can I not pull this field? Php / Mysql
Why can't i pull this field pID
from the the database?
I have the following php:
<?php
// Get course information cID, prefix, code and dept info : name
$cID = filter_input(INPUT_GET, 'cID', FILTER_SANITIZE_NUMBER_INT);
if(!$cID) {
echo "No cID specified.";
exit;
}
require_once('inc/dbc1.php');
$pdo4 = new PDO('my开发者_C百科sql:host=localhost;dbname=###', $username, $password);
$pdo4->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth4 = $pdo4->prepare('
SELECT fname, lname
FROM Course Cou, Comment Comm, Professor P
WHERE Cou.cID = ?
AND P.pID = Comm.pID
GROUP BY concat(fname, lname);
');
$sth4->execute(array(
$cID
));
?>
HTML/PHP
<a href='prof.php?pID={$row['pID']}' title='Drexel Professor Comments for {$row['fname']} {$row['lname']}'>
The above is pulling the fname and lname fields, but the first call for pID is not being pulled.
If I add pID to the select statement, it gives me the ambiguous pID error
.
Anyone??
You need to add the field to the select statement, otherwise it won't be part of the result set.
If I add pID to the select statement, it gives me the ambiguous pID error
Then make it unambiguous:
SELECT fname, lname, P.pID
should work.
Add P.pID
to your select statement since it is defined in two tables:
select P.pID
[...]
精彩评论