Results 1 to 5 of 5

Thread: Table Styling using PHP and CSS

  1. #1

    Table Styling using PHP and CSS

    Following my recent success using PHP to get data into a MySQL database I am now able to pull the data out into a respectable table. However, I would like the table to match the current styling on the site which is alternating rows of off-white and light blue. I can do this easily with xhtml and css, but I am not familiar with how it is done with dynamic returns using php and css.

    The question then is how do I assign a unique tr class to the returned results in php? Or is there a better way?

    The current css code I am using is as follows:

    Code:
    table {
    	font-size: .95em;
    	border-collapse:collapse;
    	width:41em;
    	border: 1px solid #333;
    	color:#FFFFFF;
    	}
    	
    tr td {
    	border-right: 1px solid #999;
    	border-top: 1px solid #999;
    	}
    	
    th {
    	border-right: 1px solid #999;
    }
    	
    table a:link, table a:visited {
    	text-decoration: none;
    }
    
    table a {
    	padding-left: 3px;
    }	
    
    tr.odd th	{
    	background:#00356d;
    	}
    
    tr {
    	background:#f9f4eb;
    }

  2. #2
    This is what I most commonly use:

    PHP Code:

    $res 
    mysql_query("select * from `table_name`");
    for(
    $i 0$i mysql_num_rows($res); $i++) {
       echo 
    "
          <tr class='" 
    . ($i "class_1" "class_2") . "'>
            <td>blah</td>
          </tr>
       "
    ;

    Blog: http://www.gregathons.com

    Why do web browsers function so differently? Why can't they all follow the same Web Standard...users don't care how it works, but the programmers do.

  3. #3
    gregmax

    I can see the logic here. How easily can this be adopted for a while loop?

    Thanks,

  4. #4
    I don't use while loops, hehe. (but that is just because how I learned to program, haha).

    try this:

    PHP Code:

    $x 
    0;
    while(
    notendofrows) {

      echo 
    "
          <tr class='" 
    . ($x "class_1" "class_2") . "'>
            <td>
          </tr>
      "
    ;

       
    $x++;

    I don't know the correct syntax for the while loop grabbing the data, sorry
    Blog: http://www.gregathons.com

    Why do web browsers function so differently? Why can't they all follow the same Web Standard...users don't care how it works, but the programmers do.

  5. #5
    Thanks for your help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012