php中的css样式

php中的css样式,php,css,while-loop,Php,Css,While Loop,我是新手,所以请温柔一点 我想设计例如$product\U name、$AUTHER、$details的样式。 我想我可以设计回声,但在这种情况下,唯一的回声是 <?php // Connect to the MySQL database include "storescripts/connect_mysql.php"; // This block grabs the whole list for viewing $dynamicList = ""; $sql = mysql_qu

我是新手,所以请温柔一点

我想设计例如$product\U name、$AUTHER、$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>';
$dynamicList.='

$产品名称。”

$作者。”

$细节。”
';

在头部添加一些样式:

<style>
  .product_name{color:red;}
  .author{color:green;}
  .detail{color:blue;}
</style>

.product_name{颜色:红色;}
.作者{颜色:绿色;}
.detail{颜色:蓝色;}

您可以将带有样式的类添加到包含每个值的
元素中

<td width="456"><p class="product-name">' . $product_name . '</p>...

$产品名称。”

。。。
PHP只是一个预印本,在页面加载时,在HTML的任何css启动之前,都会输出代码,以便您可以将其设置为正常样式

为什么不将css规则添加到样式表中呢

table tr td p {
// some styles
}
您可以在
段落标记以及表格单元格
上使用style=“”和class=“”参数。我想,您还可以尝试向变量添加例如样式化的
标记

例如:

$product_name = "<span class='yourstyleclass'>$row['product_name']</span>";
$product_name=“$row['product_name']”;

您想说您想为输出设置样式吗?这与您的问题有点无关,但您确实不应该使用mysql函数,因为它们已被弃用。查看如何使用mysqli_*或PDO。