+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Help!

  1. #1
    FalseHope's Avatar
    FalseHope is offline Lord Of The Keys FalseHope is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    IRC
    Posts
    1,639

    PHP Help!

    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:
    <?php
    function getline($file,$line)
    {
    $fd = fopen($file, "r");
    $liner = 0;
    while ($txt=fgets($fd)) {
    $liner++;
    if ($liner == $line) {
    $textl = $txt;
    }
    }
    fclose ($fd);
    return $textl;
    }
    echo '<table width="300" border="3"><tr><td>1</td><td align="center">'.getline('ttbc2.txt',1).'</td></tr>';
    echo '<tr><td>2</td><td align="center">'.getline('ttbc2.txt',2).'</td></tr>';
    echo '<tr><td>3</td><td align="center">'.getline('ttbc2.txt',3).'</td></tr>';
    echo '<tr><td>4</td><td align="center">'.getline('ttbc2.txt',4).'</td></tr>';
    echo '<tr><td>5</td><td align="center">'.getline('ttbc2.txt',5).'</td></tr>';
    echo '<tr><td>6</td><td align="center">'.getline('ttbc2.txt',6).'</td></tr>';
    echo '<tr><td>7</td><td align="center">'.getline('ttbc2.txt',7).'</td></tr>';
    echo '<tr><td>8</td><td align="center">'.getline('ttbc2.txt',8).'</td></tr>';
    echo '<tr><td>9</td><td align="center">'.getline('ttbc2.txt',9).'</td></tr>';
    echo '<tr><td>10</td><td align="center">'.getline('ttbc2.txt',10).'</td></tr>';
    echo '<tr><td>11</td><td align="center">'.getline('ttbc2.txt',11).'</td></tr>';
    echo '<tr><td>12</td><td align="center">'.getline('ttbc2.txt',12).'</td></tr>';
    echo '<tr><td>13</td><td align="center">'.getline('ttbc2.txt',13).'</td></tr>';
    echo '<tr><td>14</td><td align="center">'.getline('ttbc2.txt',14).'</td></tr>';
    echo '<tr><td>15</td><td align="center">'.getline('ttbc2.txt',15).'</td></tr></table>';
    ?>
    



    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 by FalseHope; 02-08-2008 at 10:55 PM.

  2. #2
    seborama is offline x10Hosting Member seborama is an unknown quantity at this point
    Join Date
    Feb 2008
    Posts
    3

    Re: PHP Help!

    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 by seborama; 02-09-2008 at 09:13 AM.

  3. #3
    Blockis2 is offline Banned Blockis2 is an unknown quantity at this point
    Join Date
    Feb 2008
    Location
    x10 Secret HeadQuarters
    Posts
    225

    Re: PHP Help!

    That Was Pretty Philosophical.

+ Reply to Thread

Similar Threads

  1. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  2. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers