有人可以帮我连接一些代码吗?
我想要的是执行此操作的代码:如果存在图片,则打印它,否则不打印任何东西。(此代码用于查找图片),我需要帮助将 if 语句连接到其他代码中的语句
<?php
$pathToFileOnDisk = 'inventory_images/' . $id . '.jpg';
if(file_exists($pathToFileOnDisk) && is_readable($pathToFileOnDisk)) {
<img src="inventory_images/' . $id . '.jpg" alt="' . $name . '" width="100%" height="260" border="1" />
}
else {
// NO IMG
}
?>
和
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php
// Run a select query to get my letest 6 items
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
$dynamicList = "";
$sql = mysql_query("SELECT * FROM content ORDER BY id DESC LIMIT 6");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$name = $row["name"];
$content = $row["content"];
$date_added = strftime("%d %b, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<div id="left">
<img src="inventory_images/' . $id . '.jpg" alt="' . $name . '" width="100%" height="260" border="1" /> <-- !!THIS IS WHAT I WANNA REPLACE!!
</div> <!-- End Left-->
</td>
<div id="right">
<td width="630px" valign="top"><h2><a id="overskrift" href="product.php?id=' . $id . '">' . $name . '</a></h2>
<p><b>
Skrevet den ' . $date_added . '<br />
' . $content . '</b></p>
</td>
</div>
</tr>
</table><br />';
}
} else {
$dynamicList = "Ingen inlegg enda..";
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
</head>
<body>
<div id="wrapper">
<header>
<?php include_once("template_header.php");?>
</header> <!-- End Header -->
<div id="banner"></div>
<div class="content test clearfix">
<?php echo $dynamicList; ?>
</div> <!-- End Content -->
<footer>
<?php include_once("template_footer.php");?>
</footer> <!-- End Footer -->
</div> <!-- End Wrapper -->
</body>