PHP Help!

FalseHope

Active Member
Messages
1,639
Reaction score
0
Points
36
I am trying to get the name of the person in the text file in one column and their total in another column. How do I do it? this is my code:
Code:
[B]<?php
[U]function[/U] getline($file,$line)
{
$fd = fopen($file, "r");
$liner = 0;
[U]while[/U] ($txt=fgets($fd)) {
$liner++;
[U]if[/U] ($liner == $line) {
$textl = $txt;
}
}
fclose ($fd);
[U]return[/U] $textl;
}
[U]echo[/U] '[B]<table width="300" border="3">[/B][B]<tr>[/B][B]<td>[/B]1[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',1).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]2[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',2).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]3[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',3).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]4[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',4).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]5[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',5).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]6[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',6).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]7[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',7).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]8[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',8).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]9[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',9).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]10[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',10).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]11[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',11).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]12[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',12).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]13[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',13).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]14[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',14).'[B]</td>[/B][B]</tr>[/B]';
[U]echo[/U] '[B]<tr>[/B][B]<td>[/B]15[B]</td>[/B][B]<td align="center">[/B]'.getline('ttbc2.txt',15).'[B]</td>[/B][B]</tr>[/B][B]</table>[/B]';
?>
[/B]

This is what it looks like:
http://www.gummiebear.x10hosting.com/template/ttbc.php
I want to split the name and number and put them in their own column.
 
Last edited:

seborama

New Member
Messages
3
Reaction score
0
Points
0
Near enough but you must think in streams: if a river passes by you and you want to dry some of its water, you have to present your glass as it goes, not after it's gone. In effect, the main while() loop means "another glass please for as long as the river runs". In your code, you are effectively making the whole river run past you 15 times! That's a lot of water passing by for a few glasses... :)

I hope this helps:



######## yourfile.php ##########################################
<html>
<head></head>
<body>
<table width="300" border="3">

<?php
$fd = fopen($file, "r"); // remember to set the "$file" variable to an existing filename!!!

if( $fd )
{
$liner = 0;

while( !feof( $fd ) )
{
$liner++;
$txt = fgets( $fd );

echo '<tr><td>'. $lineNum .'</td><td align="center">'. $txt .'</td></tr>';
}

flose( $fd );
}
else
{
echo '<tr><td>Sorry!</td><td align="center">An unexpected error occurred.</td></tr>';
}

?>

</table>
</body>
</html>
######## yourfile.php ##########################################
 
Last edited:
Top