Jump to content
MakeWebGames

Zebra Styled Tables


YoungGold

Recommended Posts

Okay now ive seen these style tables before and ive been looking to put the same thing on my game however i cant find any examples where you can use the "odd" and "even" technique to distinguish the stripes where you select the users from the db, all the examples i see are where the data is manually put it. and i have no clue on how i could do it,

Userlist.php V1

 

<?php
/*-----------------------------------------------------
-- Mono Country v1.0 BETA
-- A product of DBS-entertainment
-- Copyright held 2005 by Dabomstew
-- INDEX.php
-----------------------------------------------------*/
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$bm=money_formatter($ir['bankmoney']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$bm,$cm);
$h->menuarea();
$_GET['st'] = abs((int) $_GET['st']);
$st=($_GET['st']) ? $_GET['st'] : 0;
$by=($_GET['by']) ? $_GET['by'] : 'userid';
$ord=($_GET['ord']) ? $_GET['ord'] : 'ASC';
print "<h3>Userlist</h3>";
$cnt=mysql_query("SELECT userid FROM users",$c);
$membs=mysql_num_rows($cnt);
$pages=(int) ($membs/100)+1;
if($membs % 100 == 0)
{
$pages--;
}
print "Pages: ";
for($i=1;$i <= $pages;$i++)
{
$stl=($i-1)*100;
print "[url='userlist.php?st=$stl&by=$by&ord=$ord']$i[/url] ";
}
print "

Order By: [url='userlist.php?st=$st&by=userid&ord=$ord']User ID[/url] | [url='userlist.php?st=$st&by=username&ord=$ord']Username[/url] | [url='userlist.php?st=$st&by=level&ord=$ord']Level[/url] | [url='userlist.php?st=$st&by=money&ord=$ord']Money[/url]

[url='userlist.php?st=$st&by=$by&ord=asc']Ascending[/url] | [url='userlist.php?st=$st&by=$by&ord=desc']Descending[/url]

";
$q=mysql_query("SELECT u.*,g.* FROM users u LEFT JOIN gangs g ON u.gang=g.gangID ORDER BY $by $ord LIMIT $st,100",$c);
$no1=$st+1;
$no2=$st+100;
print "Showing users $no1 to $no2 by order of $by $ord.
<table width=75% border=2><tr style='background:gray'><th>ID</th><th>Name</th><th>Money</th><th>Level</th><th>Gender</th><th>Online</th></tr>";
while($r=mysql_fetch_array($q))
{
$d="";
if($r['donatordays']) { $r['username'] = "<font color=red>{$r['username']}</font>";$d="[img=donator.gif]"; }
print "<tr><td>{$r['userid']}</td><td>[url='viewuser.php?u={$r[']{$r['gangPREF']} {$r['username']} $d[/url]</td><td>\${$r['money']}</td><td>{$r['level']}</td><td>{$r['gender']}</td><td>";
if($r['laston'] >= time()-15*60)
{
print "<font color=green>[b][img=images/contact_blue.png][/b]</font>";
}
else
{
print "<font color=red>[b][img=images/contact_grey.png][/b]</font>";
}
print "</td></tr>";
}
print "</table>";

$h->endpage();
?>

 

p.s i remember a while back Ferdi posted a userlist before that was using this technique but i cant find it anywhere.

Link to comment
Share on other sites

Re: Zebra Styled Tables

after this...

while($r=mysql_fetch_array($q))
{

 

add something along these lines...

 

if($trcolor == '0')
{
   $color="#000000";
   $trcolor++;
}
elseif($trcolor == '1')
{
   $color="#FFFFFF";
   $trcolor--;
}

 

And use the $color to set the background color :)

Link to comment
Share on other sites

Re: Zebra Styled Tables

 

Nice unsecure userlist :mrgreen:

ill note that thank you, ive only just started and don't really care for your comment on what i know!

P.s thankyou Hauted Dawg and Lithium for staying on topic and helping me, much appreciated

 

$bg = ($tr % 2) ? '#000000' : '#FFFFFF');

 

displays an error i got over it by removing the last ')' before the ;

also

<tr style="background: ".$bg.";">

 

displays a T_STRING error so u have to remove the first and last ' " ' to solve it

After installing all that happened was the background changes to white in the table no zebra effect, i will try and fix it but if you know the fix please post it!.

Link to comment
Share on other sites

Re: Zebra Styled Tables

It's funny how all the work it takes to zebra stripe tables in PHP or JS, will simply come down to:

 

tr:nth-child(even) { background-color: #000; }

tr:nth-child(odd) { background-color: #FFF; }

 

..once all major browsers support CSS3 (or at least the nth-child attribute)

 

EDIT: So you did figure it out?

Thought I would throw out there, how I have mine set up...

 


$zebracolors = array('#FFF', '#000');

while($r=mysql_fetch_array($q))

{

  $zebra = current($zebracolors);   next($zebracolors);   (current($zebracolors) === FALSE ? reset($zebracolors) : FALSE);

  echo "<tr style='background-color:{$zebra};'>";

  //rest of userlist loop...

}

 

With this method you can use as many colors as you would like, to stripe your table with. Hope it's helpful to someone :)

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...