Page 1 of 2 12 LastLast
Results 1 to 16 of 24

Thread: Undefined offset

  1. #1
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre

    Undefined offset

    Can anyone see what is wrong with this code, its designed to read a text file and add each part to a database

    Code:
    Notice: Undefined offset: 1 in /home/n00bless/public_html/status/test/insert.php on line 16
    
    Notice: Undefined offset: 2 in /home/n00bless/public_html/status/test/insert.php on line 16
    
    Notice: Undefined offset: 3 in /home/n00bless/public_html/status/test/insert.php on line 16
    
    Notice: Undefined offset: 4 in /home/n00bless/public_html/status/test/insert.php on line 16
    
    Notice: Undefined offset: 5 in /home/n00bless/public_html/status/test/insert.php on line 16
    playerlist.txt

    Code:
    player    	GDI	100	5	2	67
    otherplayer     Nod     300     6       0       98
    PHP Code:
    <?php

     
    include ("config.php");

        
      
    $oldErrorLevel error_reporting (E_ALL);
      if ( !
    $playerlistTXT file_get_contents "playerlist.txt" ) )
       
    $updateError true;
        else
        {
        
    mysql_query "TRUNCATE TABLE status" );                    
        
    $playersArray explode "\n"$playerlistTXT );
        for ( 
    $pos 0$pos sizeof $playersArray ); $pos++ )
        {
        
    $playersArray[$pos] = explode "\t"$playersArray[$pos] );                    
        if ( !
    mysql_query "INSERT INTO status ( name, team, score, kills, deaths, ping ) VALUES ( " trim $playersArray[$pos][0] ) . ", '" str_replace "'""\'"trim $playersArray[$pos][1] ) ) . "', " trim $playersArray[$pos][2] ) . ", " trim $playersArray[$pos][3] ) . ", " trim $playersArray[$pos][4] ) . ", " trim $playersArray[$pos][5] ) . ")" ) )
        
    $criticalError "<b>An error occured while updating the database!</b><br><i>" mysql_error() . "</i>";
        }                
        
    error_reporting ($oldErrorLevel);
      }
    ?>
    Last edited by Barry; 18-01-2007 at 02:15 AM.
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  2. #2
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb
    if ( !mysql_query ( "INSERT INTO status ( name, team, score, kills, deaths, ping ) VALUES ( " . trim ( $playersArray[$pos][0] ) . ", '" . str_replace ( "'", "\'", trim ( $playersArray[$pos][1] ) ) . "', " . trim ( $playersArray[$pos][2] ) . ", " . trim ( $playersArray[$pos][3] ) . ", " . trim ( $playersArray[$pos][4] ) . ", " . trim ( $playersArray[$pos][5] ) . ")" ) )

    seems to be the line thats causing the problem.

    are you trying to explode the line so that you create a 2-dimensional array. such that

    $playersArray[0][0] = player

    ?

    can you echo the values out? it doesnt seem to like the extra [1]/[2]/etc bits

  3. #3
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    aye,

    0 = player 1 = team 2 = score 3 = kills 4 = deaths 5 = ping
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  4. #4
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb
    PHP Code:
    <?php
     
      
    if ( !$playerlistTXT file_get_contents "playerlist.txt" ) )
      {
        echo 
    "something went wrong...";
      }
     
     else
      {

       
    $playersArray explode"\n"$playerlistTXT);

       for ( 
    $i 0$i sizeof($playersArray); $i++)
        {
        
    $playersArray[$i] = explode "\t"$playersArray[$i] );
        
        
    $name   trim($playersArray[$i][0]);
        
    $team   trim($playersArray[$i][1]);
        
    $score  trim($playersArray[$i][2]);
        
    $kills  trim($playersArray[$i][3]);
        
    $deaths trim($playersArray[$i][4]);
        
    $ping   trim($playersArray[$i][5]);
        
        
    /* echo $name . ", " . $team . ", " . $score . ", " . $kills . ", " . $deaths . ", " . $ping; */

        
    $query "INSERT INTO status (name, team, score, kills, deaths, ping) values ($name$team$score$kills$deaths$ping)";
        
        
    /* if (!mysql_query($query) */
            
        
    }  
      }
    ?>
    what happens if you do this? obviously fill in the if(!mysql bit)

    its essentially the same as yours, so i dont know if it'll be any different

  5. #5
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    Same result as my layout, 1, 2 ect are all undefined
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  6. #6
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    Got your version working Streetster, thank you

    On yours the mysql_query string was missing

    PHP Code:
    <?php

     
    include ("config.php");
     
    // error_reporting(E_ALL);
     
      
    if ( !$playerlistTXT file_get_contents "playerlist.txt" ) )
      {
        echo 
    "<i>Error reading file or file emety</i>";
      }
     
     else
      {
       
    mysql_query("truncate table playerinfo");
       
    $playersArray explode"\n"$playerlistTXT);

       for ( 
    $i 0$i sizeof($playersArray); $i++)
        {
        
    $playersArray[$i] = explode "\t"$playersArray[$i] );
        
        
    $name   trim($playersArray[$i][0]);
        
    $team   trim($playersArray[$i][1]);
        
    $score  trim($playersArray[$i][2]);
        
    $kills  trim($playersArray[$i][3]);
        
    $deaths trim($playersArray[$i][4]);
        
    $ping   trim($playersArray[$i][5]);
        
    $timeplayed  trim($playersArray[$i][6]);
     
        
    // mysql_query("truncate table playerinfo");
      
    mysql_query("INSERT INTO playerinfo(name,team,score,kills,deaths,ping) VALUES('".$name."','".$team."','".$score."','".$kills."','".$deaths."','".$ping."')") or die(mysql_error());
    }
    }
    ?>
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  7. #7
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    I have 1 more problem, the text file being read (output from a perl program) has a /n causing a new line on the end making the script enter a blank entry without any values
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  8. #8
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb
    yeah, i didnt fill in the mysql bit cos i wasnt sure what you were doing hence:

    Quote Originally Posted by streetster
    what happens if you do this? obviously fill in the if(!mysql bit)
    , glad you got it working.


    as for the last line being blank, how about the following change the condition of the for statement:

    PHP Code:
    $arraysize sizeof($playersArray) -1;

    for ( 
    $i 0$i $arraysize$i++)

    ... 
    rest of code here 
    therefore reducing the number of iterations that the loop does, and removing the last /n

  9. #9
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    Great stuff!

    Final question

    I wanted to sort by scorehigh to low, this can't be done by setting the score as the prim key because it has to be unique


    I tried to use 'order by score' but that came out as

    Code:
    name               score  team
    Camper	962	NOD
    eike23	93	GDI
    MAIKBISON	864	GDI
    iggy_mon	792	NOD
    beacht	757	NOD
    {{PT}}Dentes(R)	614	GDI
    rppd69terrorist	576	NOD
    lostcost8	478	GDI
    -=(MWV)=-Ghost.Elite	405	NOD
    CiberSexyZombie	381	NOD
    bignukes9	35	NOD
    -=(MWV)=-r1chyt	275	NOD
    xtrask8er	267	GDI
    paintballPresident	233	NOD
    [BaU]RAs_EyE	22	NOD
    Mach100	2069	GDI
    pipo1294	168	GDI
    BOBOBOB	1477	GDI
    jakemosi	143	GDI
    follower5	124	NOD
    Unknownchief	1167	NOD
    [BaU]Tuandalf	1142	GDI
    [CMPS.]-{M}Snakei006	112	NOD
    doomzday	1	GDI
    Rockfruityloops	0	GDI
    appel1973	0	NOD
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  10. #10
    The King of Vague Steve B's Avatar
    Join Date
    Oct 2005
    Location
    Glasgow
    Posts
    5,051
    Thanks
    116
    Thanked
    67 times in 63 posts
    thats right for order by high score, just the tabs have gone a bit wonky, because some of the names are too long or too short!

    edit just noticed its completely wrong, forgive me lol
    Last edited by Steve B; 19-01-2007 at 12:54 AM.

  11. #11
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb
    we're getting there...

    As for the ordering... how have you defined the 'score' table in the database? is it of type INT? if so then the sorting by score should work ie:

    PHP Code:
    $query"SELECT name, score, team FROM playerinfo ORDER BY score DESC";


    $result mysql($query);

    while(
    $row mysql_fetch_array($result))
    {

    /* process the result here */






    Quote Originally Posted by Steve B View Post
    thats right for order by high score, just the tabs have gone a bit wonky, because some of the names are too long or too short!
    not quite, if you look towards the bottom you can see a score of 1167... not quite right. I'd make sure that the field is defined as an integer

  12. #12
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    It just looks neater!

    Code:
    for ($i = 0; $i < sizeof($playersArray-1); $i++)
    You know you could use the file pointer and fgets() to just read the text file a single line at a time, rather than exploding the file into two separate arrays.
    To err is human. To really foul things up ... you need a computer.

  13. #13
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    It just looks neater!

    Code:
    for ($i = 0; $i < sizeof($playersArray-1); $i++)
    You know you could use the file pointer and fgets() to just read the text file a single line at a time, rather than exploding the file into two separate arrays i.e.

    Code:
    $data = fgets($fp);
    Should simply read a single line and place the pointer at the correct position when a CR/CR-LF is encountered.
    To err is human. To really foul things up ... you need a computer.

  14. #14
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts
    Ok multi-postage I apologise. For this one too.
    To err is human. To really foul things up ... you need a computer.

  15. #15
    You're god damn right Barry's Avatar
    Join Date
    Jul 2003
    Posts
    1,484
    Thanks
    70
    Thanked
    75 times in 59 posts
    • Barry's system
      • Motherboard:
      • Gigabyte Z270M-D3H
      • CPU:
      • Intel i7 7700
      • Memory:
      • 16GB (2x8GB) Avexir 2400
      • Storage:
      • Samsung 860 256GB SSD, Sandisk Ultra 3D 500GB, LG BR Writer
      • Graphics card(s):
      • Evga GeForce GTX Titan X 12GB
      • PSU:
      • Corsair RM750I
      • Case:
      • Fractal Design Focus G
      • Operating System:
      • Windows 10 Professional
      • Monitor(s):
      • 28" Acer UHD 4K2K
      • Internet:
      • Sky Fibre
    Thank you streetster
    Someone left a note on a piece of cake in the fridge that said, "Do not eat!". I ate the cake and left a note saying, "Yuck, who the hell eats paper ?

  16. #16
    cat /dev/null streetster's Avatar
    Join Date
    Jul 2003
    Location
    London
    Posts
    4,138
    Thanks
    119
    Thanked
    100 times in 82 posts
    • streetster's system
      • Motherboard:
      • Asus P7P55D-E
      • CPU:
      • Intel i5 750 2.67 @ 4.0Ghz
      • Memory:
      • 4GB Corsair XMS DDR3
      • Storage:
      • 2x1TB Drives [RAID0]
      • Graphics card(s):
      • 2xSapphire HD 4870 512MB CrossFireX
      • PSU:
      • Corsair HX520W
      • Case:
      • Coolermaster Black Widow
      • Operating System:
      • Windows 7 x64
      • Monitor(s):
      • DELL U2311
      • Internet:
      • Virgin 50Mb
    does that mean you've sorted the sorting issue? maybe you could post the whole code, for future reference glad i could help tho buddy.. keep the PHP problems coming tho, helps me avoid my revision!

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need a file player with audio offset
    By Norky in forum Consumer Electronics
    Replies: 3
    Last Post: 11-04-2005, 11:38 AM
  2. VCore Voltage Offset
    By Taz in forum PC Hardware and Components
    Replies: 5
    Last Post: 10-02-2005, 06:00 PM
  3. ET and offset?
    By praetorian in forum Automotive
    Replies: 1
    Last Post: 18-11-2003, 04:49 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
  •