お願いします、これはphpを使ったmysqliでの私の最初の試みです。結果をテーブルに出力しようとしていますが、テーブルにデータが表示されません。
私は以前に試しました
printf( "%s%s \ n"、$ c_id、$ ctitle);
正しい結果が印刷されました。しかし、私は結果を表にしたいと思っています。
これをメインページのアイテムにリンクする詳細ページにするつもりです。私のコード:
<?php
$mysqli = new mysqli("localhost", "joseph", " ", "collectionsdb");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($stmt = $mysqli->prepare("SELECT c_id,ctitle,csubject,creference,cyear,cobjecttype,cmaterial,ctechnic,cwidth,cheight,cperiod,cmarkings,cdescription,csource,cartist,cfilename FROM collections ORDER BY c_id")) {
/* Execute the prepared Statement */
$stmt->execute();
/* Bind results to variables */
$stmt->bind_result($c_id,$ctitle,$csubject,$creference,$cyear,$cobjecttype,$cmaterial,$ctechnic,$cwidth,$cheight,$cperiod,$cmarkings,$cdescription,$csource,$cartist,$cfilename);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">
<body>
<?php
/* fetch values */
while ($rows = $stmt->fetch()) {
// print image and data into a html table ??
?>
<table border="1" align="left">
<tr>
<td rowspan=16> <?php echo '<img src="./images/'.$rows['cfilename'].'" width="300" height="400" />'; ?> </td>
</tr>
<tr><td>ID</td><td><?php echo $rows['c_id']; ?></td></tr>
<tr><td>TITLE</td><td><?php echo $rows['ctitle']; ?></td></tr>
<tr><td>SUBJECT</td><td><?php echo $rows['csubject']; ?></td></tr>
<tr><td>REFERENCE No.</td><td><?php echo $rows['creference']; ?></td></tr>
<tr><td>YEAR</td><td><?php echo $rows['cyear']; ?></td></tr>
<tr><td>OBJECT TYPE</td><td><?php echo $rows['cobjecttype']; ?></td></tr>
<tr><td>MATERIAL USED</td><td><?php echo $rows['cmaterial']; ?></td></tr>
<tr><td>TECHNIC</td><td><?php echo $rows['ctechnic']; ?></td></tr>
<tr><td>WIDTH</td><td><?php echo $rows['cwidth']; ?></td></tr>
<tr><td>HEIGHT</td><td><?php echo $rows['cheight']; ?></td></tr>
<tr><td>PERIOD</td><td><?php echo $rows['cperiod']; ?></td></tr>
<tr><td>MARKINGS</td><td><?php echo $rows['cmarkings']; ?></td></tr>
<tr><td>DESCRIPTION</td><td><?php echo $rows['cdescription']; ?></td></tr>
<tr><td>SOURCE</td><td><?php echo $rows['csource']; ?></td></tr>
<tr><td>ARTIST</td><td><?php echo $rows['cartist']; ?></td></tr>
</table>
<?php
}
/* Close the statement */
$stmt->close();
}
else {
/* Error */
printf("Prepared Statement Error: %s\n", $mysqli->error);
}
/* close our connection */
$mysqli->close();
?>
ありがとうございました。
ジョセフ