2013-07-07 55 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>";