开发者

Sql failing to calling fields correctly

开发者 https://www.devze.com 2023-02-21 15:44 出处:网络
The php/sql calling this: <?php // Filter our input开发者_开发技巧. $pID = filter_input(INPUT_GET, \'pID\', FILTER_SANITIZE_NUMBER_INT);

The php/sql calling this:

<?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
));

The other php code:

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);
                    ?>

Sql failing to calling fields correctly

Sql failing to calling fields correctly

Why arent these two fields 'picpath' and 'name' being pulled?? Its not throwing any error. Above are the two db fields:


I suspect you have numerous errors with your initial SQL Query.

I suggest you read up on MySQL JOIN. Considering I understood how that query was supposed to be run try this:

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 = ?
0

精彩评论

暂无评论...
验证码 换一张
取 消