-2
這沒有submiting形式是我的代碼:
<?php
require_once('config.php');
/*
Displays the list of artist links on the left-side of page
*/
function outputArtists() {
try {
$pdo = new PDO(DBCONNSTRING,DBUSER,DBPASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "select * from Artists order by LastName limit 0,15";
$result = $pdo->query($sql);
while ($row = $result->fetch()) {
echo '<a href="lab11-exercise10.php?id=' . $row['ArtistID'] . '" class="list-group-item';
if (isset($_GET['id']) && $_GET['id'] == $row['ArtistID']) echo ' active';
echo '">';
echo $row['LastName'] . '</a>';
}
$pdo = null;
}
catch (PDOException $e) {
die($e->getMessage());
}
}
/*
Displays the list of paintings for the artist id specified in the id query string
*/
function outputPaintings() {
try {
if (isset($_GET['id']) && $_GET['id'] > 0) {
$pdo = new PDO(DBCONNSTRING,DBUSER,DBPASS);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = 'select * from ArtWorks where ArtistId=' ;
$id = $_GET['id'];
$statement = $pdo->prepare($sql);
$statement->bindValue(':id', $id);
$statement->execute();
while ($row = $statement ->fetch()) {
outputSinglePainting($row);
}
$pdo = null;
}
}
catch (PDOException $e) {
die($e->getMessage());
}
}
/*
Displays a single painting
*/
function outputSinglePainting($row) {
echo '<div class="media">';
echo '<a class="pull-left" href="#">';
echo '<img class="media-object" src="images/art/works/square-medium/' . $row['ImageFileName'] .'.jpg">';
echo '</a>';
echo '<div class="media-body">';
echo '<h4 class="media-heading">';
echo htmlentities($row['Title'], ENT_IGNORE | ENT_HTML5, "ISO-8859-1");
echo '</h4>';
echo $row['Description'];
echo '</div>';
echo '</div>';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 11</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap3_defaultTheme/dist/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div class="well"><h1>User Input (pdo)</h1></div>
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="list-group">
<?php outputArtists(); ?>
</div>
</div>
<div class="col-md-9">
<?php outputPaintings(); ?>
</div>
</div>
</div>
</body>
</html>
我不太清楚什麼呢$ _GET [「身份證」]的意思。根據我的理解,當提交類似於提交表單的名稱=「XXX」時,我們使用$ _GET,然後使用$ _GET ['XXX']。但是這段代碼中沒有'id',爲什麼它使用$ _GET ['id']> 0或$ _GET ['id'] == $ row ['ArtistID']?在這種情況下,$ _GET ['id']的含義是什麼?
你已經指定'echo' Thamilan
你有沒有見過像'somepage.php?a = b&c = d'這樣的地址?問號後面的部分是填充$ _GET數組的東西 –
你也可以使用$ _GET從url傳遞值,例如page.php?id = 1。在這種情況下,你將在$ _GET中得到1 ['id']變量 – Bhavik