我是新手,所以请温和
例如,我想设置$product_name、$author、$details的样式。我想我可以确定回声的样式,但在这种情况下,唯一的回声是
<?php
// Connect to the MySQL database
include "storescripts/connect_mysql.php";
// This block grabs the whole list for viewing
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY id DESC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$author = $row["author"];
$details = $row["details"];
$link = $row["link"];
$isbn = $row["isbn"];
$isbn13 = $row["isbn13"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="580" border="0" cellspacing="0">
<tr>
<td width="120"><img src="/inventory_images/' . $id . '.jpg" width="120" height="184" border="0" /></td>
<td width="456"><p>' . $product_name . '<p><br />
<p>' . $author . '</span><br />
<p>' . $details . '<br />
<a href="product.php?' . $id . '">visa </a></td>
</tr>
</table>';
}
} else {
$dynamicList = "Database empty.";
}
mysql_close();
?>
您是否尝试过将一些CSS类添加到表单元格中?
$dynamicList .= '
<table width="580" border="0" cellspacing="0">
<tr>
<td width="120"><img src="/inventory_images/' . $id . '.jpg" width="120" height="184" border="0" /></td>
<td width="456"><p class="product_name">' . $product_name . '<p><br />
<p class="author">' . $author . '</span><br />
<p class="detail">' . $details . '<br />
<a href="product.php?' . $id . '">visa </a></td>
</tr>
</table>';
在头部添加一些样式:
<style>
.product_name{color:red;}
.author{color:green;}
.detail{color:blue;}
</style>
为什么不在样式表中添加CSS规则呢?
table tr td p {
// some styles
}
您可以向包含每个值的<p>
元素添加带有样式的类
<td width="456"><p class="product-name">' . $product_name . '</p>...
PHP只是一个预处理程序,在页面加载时和HTML的任何css启动之前都会编译代码,因此您可以将其设置为正常的样式。
您可以在<p>
段落标记和表单元格<td>
上使用style="和class="参数。我想,您还可以尝试将样式化的<span>
或<div>
标记添加到您的变量中。
例如:
$product_name = "<span class='yourstyleclass'>$row['product_name']</span>";