在產品數據庫中顯示產品目前,我能夠根據產品類別實現所需產品。不過,我覺得我這樣做並不是最好的方式。在產品頁面上,產品頂部和底部之間存在空隙HERE。我假設差距是由於我的PHP代碼中的錯誤,而不是我在佈局HTML的方式。任何幫助將不勝感激。根據類別ID
因此,爲了澄清我在想,如果使用的代碼是實現這一目標的正確方法,並且任何人都可以發現差距爲什麼會是完美的。
只是爲了澄清它顯然不是一個問題與CSS。沒有保證金適用,我想黑線完全消失。它應該是全白的。
謝謝你,祝你有個美好的新年。
PHP代碼
<?php
function get_posts($id = null, $cat_id = null) {
$posts = array();
$query ="SELECT `products`.`id` AS `name` , `products_cat`.`id` AS `category_id` , `products`.`name` AS `title` , `description` , `price` , `sale` , `picture`
FROM `products`
INNER JOIN `products_cat` ON `products`.`prod_id` = `products_cat`.`id` ";
if (isset($id)) {
$id = (int) $id;
$query .= " WHERE `products`.`id` = {$id}";
}
if (isset($cat_id)) {
$cat_id = (int) $cat_id;
$query .= " WHERE `products_cat`.`id` = {$cat_id}";
}
$query .= " ORDER BY `products`.`price` DESC";
$query = mysql_query($query);
echo mysql_error();
while ($row = mysql_fetch_assoc($query)) {
$posts[] = $row;
}
return $posts;
}
function category_exists($field, $value) {
$field = mysql_real_escape_string($field);
$value = mysql_real_escape_string($value);
$query = mysql_query("SELECT COUNT(1) FROM `products_cat` WHERE `{$field}` = '{$value}'");
echo mysql_error();
return (mysql_result($query, 0) == '0') ? false : true;
}
?>
HTML代碼
<?php
include("../script/dbconnect.php");
include("../script/get_product.php");
$posts = get_posts(null, $_GET['id']);
?>
<div style="width:100%; height:150px; background-color:white;"><span style="font-family:saxMonoRegular; letter-spacing:2px; display:block; font-size:4.5em; text-align:center; padding-top:15px;"> Blog </span></div>
<div class="link" style="width:100%; background-color: white">
<?php
foreach ($posts as $post) {
if (! category_exists('name', $post['name'])) {
$post['name'] = 'Uncategorised';
}
?>
<ul class='featured'>
<li class='headhighlight'><?php echo $post['title']; ?></li>
<li class='pricehigh'><?php echo $post['price']; ?></li>
<li class='imagefeat'><img class='imagelink' src='<?php echo $post['picture']; ?>' alt='$name'></li>
</ul>
<?php
}
?>
</div>
你的意思是這差距?你可以在紅色的圖像上顯示這些差距嗎? –
上面的鏈接中有一個圖像。它是產品頂部和底部之間的黑色線條。 http://www.imagesocket.com/photos/guest/2563264 – memyselfandmyiphone
對不起,我一直在喋喋不休,但請停止使用_deprecated_'mysql_ *'擴展名。改用'PDO'或'mysqli_ *'(注意'mysqli_ *'中的'i',代表_improved_) –