0

I'm new to this so please be gentle

I want to style for example $product_name, $author, $details. I guess I could style the echos but in this case the only echo is

<?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();
?>
2
  • 1
    Do you want to say that you want to style the output? Commented Jul 7, 2013 at 17:00
  • this is sort of unrelated to your question, but you really should not be using the mysql_* functions as they are deprecated. Look up how to use mysqli_* or PDO. Commented Jul 7, 2013 at 17:01

5 Answers 5

1

Have you tried adding some CSS classes to your table cells?

$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>';

In the head add some styles:

<style>
  .product_name{color:red;}
  .author{color:green;}
  .detail{color:blue;}
</style>
Sign up to request clarification or add additional context in comments.

Comments

1

Why not just add CSS rules to your stylesheet?

table tr td p {
// some styles
}

Comments

0

You can add a class with styles to the <p> elements that contain each value

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

Comments

0

PHP is only a preprocssor and coughs up the code as the page loads and before any of the css of HTML kicks in so you can style it as normal

Comments

0

You can use style="" and class="" parameters on your <p> paragraph tags as well on the table cells <td>. You can also try to add for example styled <span> or <div> tags to your variables I suppose.

For example:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.