Jump to content
Sign in to follow this  
LimitedStreak

Css - database

Recommended Posts

echo "<table>";

$sql = "SELECT field1, field2, field3 FROM table ORDER BY field1 LIMIT 20";
$rs  = mysql_query($sql);
$odd = 1;

while ($row = mysql_fetch_array($rs))
{
   echo sprintf('<tr class="%s">', $odd ? "odd" : "even");
#   echo "<tr>";  commented out to appease the pedantic fool below
   echo "<td>" . htmlentities($row[0]) . "</td>";
   echo "<td>" . htmlentities($row[1]) . "</td>";
   echo "<td>" . htmlentities($row[2]) . "</td>";
   echo "</tr>";

   $odd = 1 - $odd;
}

mysql_free_result($rs);

echo "</table>";
Edited by Anonymous

Share this post


Link to post
Share on other sites

mate i really not sure what you did.

Its a table just say this, where would i put the odd, even?

 

<table width="300" border="0" cellpadding="0" cellspacing="0" class="table">







<tr class="thinline" class="table_back">







<td colspan=2>



     Last 10 Registered</td>



   </tr>



       <tr class=table>



         <td class="subhead" width="109">Username</td>



         <td class="subhead" width="126">Date/time</td>



       </tr>



       <?



   $c=mysql_query("SELECT * FROM users ORDER BY id DESC LIMIT 10");



   while($d=mysql_fetch_object($c)){



   echo "<tr><td align=left><a href='profile.php?viewuser=$d->username'>$d->username</a></td><td>$d->regged</td></tr>";















   }



   ?>



   </table></td>
Edited by Nickson
added code tags

Share this post


Link to post
Share on other sites

Added code tags, please use these in the future, as well as remove unneeded empty lines...

Also, this is basic html knowledge in combination of nested tables.

Anonymous has posted an example of how you could do it properly, of course you need to edit that code to suit YOUR needs. But I'm quite sure you'll have to do that yourself... Afterall, if you can own a game, you should be able to do this by yourself, it's not rocket science ;)

Share this post


Link to post
Share on other sites

There is one key feature to it:

echo sprintf('<tr class="%s">', $odd ? "odd" : "even");

which suggests you do similar. You are echo'ing a <tr> element ... change yours to suit.

echo "<tr class=\"xxx\"><td align=left><a href='profile.php?viewuser=$d->username'>$d->username</a></td><td>$d->regged</td></tr>";

Replace xxx with odd/even to suit. You will of course have to provide a mechanism to flip odd to even and back again - and of course the css to support odd/even rows, but that I leave as an exercise.

While I don't mean to sound harsh - perhaps the "Website Developer - Willing to help you!" tag in your sig is overly optimistic?

Share this post


Link to post
Share on other sites

It would probably be easier to do it in css

[CSS]table > tbody > td:odd { background-color:#0f0; }

table > tbody > td:even { background-color:#f00; }[/CSS]

Edited by bluegman991

Share this post


Link to post
Share on other sites

Indeed, but some pedants here dislike people suggesting CSS-3. At least this way there's a chance it will work in everything back to pre IE6 days.

Share this post


Link to post
Share on other sites

I do exactly the opposite ...

add this under your while statement...as shown in example...

while($d=mysql_fetch_object($c)){

$bgcolor = ($bgcolor == "#ececec") ? "#ffffff" : "#ececec";

then for your <tr> tag add...

<tr style='background-color: ".$bgcolor ."'>

and your done, really simple and easy!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...