adding css to my php script

Discussion in 'PHP' started by rojojat, Feb 14, 2009.

  1. #1
    Hello
    I have a simple php script that retreives information from a database and inserts it into an html table. How would I apply css to this script so that the output isn't so plain?Thank You.


    <?php
    include("passwords_db.inc");
    include("connect_mysql.inc");
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql)
    or die("Couldn't execute QUERY.");

    echo '<table align="center"border="1">
    <tr> <td> firstname</td> <td> lastname</td><td>email</td><td>username</td><td>mailing address</td><td>city</td><td>state</td><td>phone</td><td>zipcode</td></tr>';

    while ($row=mysql_fetch_array($result,MYSQL_ASSOC))
    echo '<tr><td>'. $row['firstname'].'</td>'. '<td>'.$row['lastname'].'</td>'.
    '<td>'.$row['email'].'</td>'.
    '<td>'.$row['user'].'</td>'.
    '<td>'.$row['address'].'</td>'.
    '<td>'.$row['city'].'</td>'.
    '<td>'.$row['state'].'</td>'.
    '<td>'.$row['area'].$row['prefix'].$row['number'].'</td>'.
    '<td>'.$row['zipcode'].'</td></tr>';
    ?>
     
    rojojat, Feb 14, 2009 IP
  2. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Hello rojojat,

    First of all is this PHP codes embedded into already existing HTML file or its just the result HTML page, if it is the second option then you need to make it as a complete HTML page by including <HTML><BODY> open and close tag. Now include the CSS file in header tag in either option. Create a CSS class for your TABLE and put on whatever styles you are looking for. You can also create multiple classes for multiple options eg. TR TD DIV etc.

    Regards,
    Gonzo
     
    Gonzo4u, Feb 14, 2009 IP
  3. beezzee

    beezzee Peon

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    add this before "<?php"
    <style>
    body {
    font-family:Trebuchet MS,Helvetica,Arial,sans-serif;
    }
    ... etc .. etc ...
    </style>

    <html>, <body> and other stuff are not necessary
     
    beezzee, Feb 14, 2009 IP
  4. tn5421

    tn5421 Active Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    56
    #4
    <?php
    include("passwords_db.inc");
    include("connect_mysql.inc");
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql)
    or die("Couldn't execute QUERY.");
    include("table_styles.css"); /* Make a seperate file called this and store it in the same directory */

    echo '<table align="center"border="1">
    <tr> <td> firstname</td> <td> lastname</td><td>email</td><td>username</td><td>mailing address</td><td>city</td><td>state</td><td>phone</td><td>zipcode</td></tr>';

    while ($row=mysql_fetch_array($result,MYSQL_ASSOC))
    echo '<tr><td>'. $row['firstname'].'</td>'. '<td>'.$row['lastname'].'</td>'.
    '<td>'.$row['email'].'</td>'.
    '<td>'.$row['user'].'</td>'.
    '<td>'.$row['address'].'</td>'.
    '<td>'.$row['city'].'</td>'.
    '<td>'.$row['state'].'</td>'.
    '<td>'.$row['area'].$row['prefix'].$row['number'].'</td>'.
    '<td>'.$row['zipcode'].'</td></tr>';
    ?>
     
    tn5421, Feb 14, 2009 IP
  5. rojojat

    rojojat Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank You everyone,

    beezzee, your way works. I tried doing include("table_styles.css"); but it just displayed the style sheet contents at the top of the page.
     
    rojojat, Feb 14, 2009 IP
  6. Asus-Games

    Asus-Games Peon

    Messages:
    582
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That's becuase it tried to read the style sheet like a PHP file, since it wasn't a PHP file it assumed it was plain text and just spit it out.
     
    Asus-Games, Feb 14, 2009 IP
  7. AndreasB

    AndreasB Peon

    Messages:
    280
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    To link to an external CSS file, you have to put this code between your <head> tags:
    <link rel="stylesheet" type="text/css" href="FILENAME.css" />
     
    AndreasB, Feb 15, 2009 IP
  8. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #8
    I guess you didnt read my post.
     
    Gonzo4u, Feb 15, 2009 IP
  9. rojojat

    rojojat Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    gonzo4u,
    I guess I did not understand your post. I am new to this.
     
    rojojat, Feb 15, 2009 IP
  10. Gonzo4u

    Gonzo4u Well-Known Member

    Messages:
    410
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #10
    I see!

    Well if your problem is solved fine otherwise you can send me a PM and I will explain you in detail how to do it.

    Gonzo
     
    Gonzo4u, Feb 15, 2009 IP
  11. Acecool

    Acecool Peon

    Messages:
    267
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #11
    .inc files are viewable as TEXT in a browser window... Change the extension to .php for security!
     
    Acecool, Feb 15, 2009 IP