拜托,这是我第一次使用 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();
?>
谢谢你。
约瑟夫