Jump to content
MakeWebGames

Css - database


LimitedStreak

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
Link to comment
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
Link to comment
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 ;)

Link to comment
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?

Link to comment
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!

Link to comment
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.

×
×
  • Create New...