2013-07-07 48 views
0

我对此很陌生,所以请保持温柔在php中使用css样式

我想要样式,例如$ 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(); 
?> 
+1

你想说,你想样式的输出? – 2013-07-07 17:00:17

+0

这与你的问题无关,但你真的不应该使用mysql_ *函数,因为它们已被弃用。看看如何使用mysqli_ *或PDO。 – vijrox

回答

1

您是否尝试添加一些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> 
0

您可以添加类样式包含每个值

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

PHP的<p>元素仅仅是一个preprocssor咳嗽随着页面加载和HTML的任何css开始之前的代码,以便您可以风格它正常

1

为什么不把CSS规则添加到样式表中?

table tr td p { 
// some styles 
} 
0

您可以使用样式=“”和class =“你的<p>段落标记”参数,以及在表格单元格<td>。您也可以尝试添加例如样式<span><div>标签到您想要的变量。

例如:

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