Numbering HTML Table rows
07-11-05, 03:28 AM
Newbie Coder
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Numbering HTML Table rows
Ok this is driving me nuts, i am working on a script that ranks a players points in order from most to least, ive managed to do this but I cant seem to get my output table (HTML) to rank the tables incrementally... In other words i want a table to go
RANK | MEMBER ID | TOTAL POINTS
-----------------------------------------
1 | XXX-XXX-X | 10000
2 | XXX-XXX-X | 8000
3 | XXX-XXX-X | 7000
4 | XXX-XXX-X | 1000
4 | XXX-XXX-X | 100
where the "rank" number is incremented as the HTML table is output to the page
------------
The code i have so far is this, and i need a function that will increment this number for me
------------
PHP Code:
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th width="50" align="left"><font face="Arial, Helvetica, sans-serif" size="2">
Rank</font></th>
<th width="300" align="left"><font face="Arial, Helvetica, sans-serif" size="2">
Player Name</font></th>
<th width="75" align="left"><font face="Arial, Helvetica, sans-serif" size="2">
Total Points</font></th>
</tr>
<?
$user = "lxxxx" ;
$password = "lxxxxx" ;
$database = "lxxxxxx" ;
mysql_connect ( localhost , $user , $password );
@ mysql_select_db ( $database ) or die( "Unable to select database" );
$query = "SELECT * FROM rank_point ORDER BY total_points ASC" ;
$result = mysql_query ( $query );
$num = mysql_numrows ( $result );
mysql_close ();
$i = 0 ;
while ( $i < $num ) {
//$pid=mysql_result($result,$i,"pid");
$fname = mysql_result ( $result , $i , "fname" );
$lname = mysql_result ( $result , $i , "lname" );
//$email=mysql_result($result,$i,"email");
//$bdate=mysql_result($result,$i,"bdate");
//$sdate=mysql_result($result,$i,"sdate");
$pname = $lname , $fname ;
$tpoints = "500" ;
?>
<tr>
<td width="50"><font face="Arial, Helvetica, sans-serif" size="2"><? echo $rank ; ?> </font></td>
<td width="300"><font face="Arial, Helvetica, sans-serif" size="2"><? echo $pname ; ?> </font></td>
<td width="75"><font face="Arial, Helvetica, sans-serif" size="2"><? echo $tpoints ; ?> </font></td>
</tr>
<?
$i ++;
}
echo "</table>" ;
?>
and the particualr line im after fixing is this
where $rank should call a function that incremnts it by 1
please help, i need to get this script running ASAP
also all of the crappy coding is because i am piecing the script togtether piece by piece until i have each part working on its own.. thought id share that beofre someone comments on how sloppy it is
Last edited by lppa2004; 07-11-05 at 03:30 AM .
07-12-05, 02:19 AM
Wannabe Coder
Join Date: Jun 2004
Location: In a nice house.
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Simply print or echo $i in your <td> tag.
07-12-05, 03:14 AM
Code Guru
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
There are so many mistakes I am suprised it works at all!
Firstly you use 'mysql_close();' then try to do a 'mysql_result' with no connection to the database!
Secondly you have:
$pname = $lname, $fname;
That is invalid syntax, it should be:
$pname = $lname .",". $fname;
Thirdly you haven't defined $rank, you need to put:
$rank = $i;
Or just use <? echo $i; ?> not <? echo $rank; ?>
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.
codR.us <-- Submit and vote for your favorite code snippets with codR.us.
XEWeb.net <-- The ultimate PHP resource network.
07-12-05, 01:26 PM
Newbie Coder
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
okay that worked except the first rank table is 0, i need it to be 1
07-12-05, 04:22 PM
Code Guru
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
can u not read ur own code?
$i=0;
there's a clue...
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.
codR.us <-- Submit and vote for your favorite code snippets with codR.us.
XEWeb.net <-- The ultimate PHP resource network.
07-12-05, 04:55 PM
Level II Curmudgeon
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by FiRe
can u not read ur own code?
$i=0;
there's a clue...
Lol, my thoughts exactly.
07-12-05, 10:51 PM
Newbie Coder
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
yeah so im quite new to PHP coding, and still learning... hence why i came here for help.
Im sure there was a point when you all were learning the language , that it could of easily slipped by you too...
Sorry... im not a PHP genius... If i was, i sure wouldnt be asking for help :-)
07-13-05, 04:05 AM
Code Guru
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
no you dont have to be a genius but you have to know the basics of PHP otherwise people like me just get fed up of stupid questions!
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.
codR.us <-- Submit and vote for your favorite code snippets with codR.us.
XEWeb.net <-- The ultimate PHP resource network.
07-13-05, 06:50 AM
Newbie Coder
Join Date: Oct 2004
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
the only stupid question is one that is left unasked.
Plus im teaching myself PHP, so i dont know all of the basics.. Besides, i dont think anywhere on this forum does it imply that you need to know "the basics" of PHP or programinng in general to be asking questions...
I came here for help, and i do appreciate the help you gave, but i think the way it was given was a bit rude, it was somewhat condescending and a bit cocky (kinda like, look im a great coder and your not, etc etc) If i knew the basics, do you really think id of been asking help on something that is so basic.. and yes i do realize that my problem was something that any "taught" programmer would have known, but self teaching is a whole nother story... If i had an actual book in front of me about PHP i probabbly wouldnt of needed to ask, but trying to find the info completely online from tutorials and such, leaves alot to be desired
Once again thanks for the help, but try not to make the person asking feel like they are "stupid"... Besides most "stupid" people wouldnt even be attempting to program, they would hire someone to do it for them
07-13-05, 07:13 AM
Code Guru
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
all i can say RTFM! end of discussion...
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.
codR.us <-- Submit and vote for your favorite code snippets with codR.us.
XEWeb.net <-- The ultimate PHP resource network.
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off