Current location: Hot Scripts Forums » Programming Languages » PHP » Numbering HTML Table rows


Numbering HTML Table rows

Reply
  #1 (permalink)  
Old 07-11-05, 03:28 AM
lppa2004 lppa2004 is offline
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

PHP Code:

<td width="50"><font face="Arial, Helvetica, sans-serif" size="2"><? echo $rank?></font></td>
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.
Reply With Quote
  #2 (permalink)  
Old 07-12-05, 02:19 AM
php~pro php~pro is offline
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.
Reply With Quote
  #3 (permalink)  
Old 07-12-05, 03:14 AM
FiRe FiRe is offline
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.
Reply With Quote
  #4 (permalink)  
Old 07-12-05, 01:26 PM
lppa2004 lppa2004 is offline
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
Reply With Quote
  #5 (permalink)  
Old 07-12-05, 04:22 PM
FiRe FiRe is offline
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.
Reply With Quote
  #6 (permalink)  
Old 07-12-05, 04:55 PM
End User's Avatar
End User End User is offline
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.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #7 (permalink)  
Old 07-12-05, 10:51 PM
lppa2004 lppa2004 is offline
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 :-)
Reply With Quote
  #8 (permalink)  
Old 07-13-05, 04:05 AM
FiRe FiRe is offline
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.
Reply With Quote
  #9 (permalink)  
Old 07-13-05, 06:50 AM
lppa2004 lppa2004 is offline
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
Reply With Quote
  #10 (permalink)  
Old 07-13-05, 07:13 AM
FiRe FiRe is offline
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.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
html tutoral thefrtman HTML/XHTML/XML 5 04-27-09 10:25 AM
Problem with counting rows in a table kittenesque PHP 5 06-23-05 09:21 AM
Using SELECT COUNT(*) as Num on a table with no rows. ozwald PHP 16 04-30-05 10:18 AM
Advice parsing a html table to xml RossC0 JavaScript 3 03-22-05 02:10 PM
Problem with a sort table js function tdubyou JavaScript 0 05-03-04 09:19 AM


All times are GMT -5. The time now is 06:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.