-2

Hi guys as the title says i'm trying to clear My SQL table before importing new data , but the problem only the last two rows appears not all of them .

I tried this using "TRUNCATE"

// clear table
$sqli = "TRUNCATE TABLE MyTable";
mysql_query($sqli);


$sql = 'INSERT INTO MyTable VALUES("'.$Data1.'","'.$Data2.'") ';
mysql_query($sql);
mysql_close();


$sql = 'SELECT * FROM MyTable';
    $req = mysql_query($sql);
    while($data = mysql_fetch_array($req)){
        $D1 = $data['data1'];
        $D2 = $data['data2'];
        echo "$D1<br />
        $D2<br />";
    }

i can see only the last two rows.

M. Walid
  • 15
  • 1

1 Answers1

0

this is full code

part 1 : adding data into MySQL table

<?php
include( "............" );

$table = mta::getInput();
$Kills = $table[0];
$Deaths = $table[1];

// Send infos in MySQL
$base = mysql_connect ('........', '.........', '........');
mysql_select_db ('.........', $base);

$sql = 'INSERT INTO AccountsData VALUES("'.$Kills.'","'.$Deaths.'") ';
mysql_query($sql);
mysql_close();

// Return true if is added
// an other code here
?>

part 2 : get data from Mysql Table

<?php
    $base = mysql_connect ('.........', '.........', '.........');
    mysql_select_db ('..........', $base);

    $sql = 'SELECT * FROM AccountsData';
    $req = mysql_query($sql);
    while($data = mysql_fetch_array($req)){
        $Kills = $data['Kills'];
        $Deaths = $data['Deaths'];
        echo "$Kills<br />
        $Deaths<br />";
    }
    mysql_close();
?>

before using "TRUNCATE TABLE" it's working fine and i can see all rows

like this:

example

  1. player 1
  2. player 2
  3. player 3
  4. player 4

after using "TRUNCATE TABLE" i can see only the last row

  1. player 4.

All what i need is i want to clear the table before adding new rows.

Sorry it's the first time that i use https://stackoverflow.com/

Community
  • 1
  • 1
M. Walid
  • 15
  • 1