Pulling data from SQL, and writing to a text file

前端 未结 7 1096
广开言路
广开言路 2021-01-07 01:28

I am trying to pull data from SQL, and then write it to a text file. This does that, to an extent, but it only pulls 1 from the table, which reads test:test<

相关标签:
7条回答
  • 2021-01-07 01:59

    You're not appending your database results to the $accounts string; you're creating it from scratch each time. Try something like this:

    <?php
    $accounts = "";
    $sql = mysql_query("SELECT * FROM _$setprofile ORDER BY fc DESC");
    while($row = mysql_fetch_array($sql)) {
      $user = $row['user'];
      $pass = $row['pass'];
    
      $accounts .= "$user:$pass<br>";
    }
    
    //Functionsss!
    $file = "backups/$newcode.txt";
    file_put_contents($file, $accounts);
    
    echo "<a href=backups/$newcode.txt>TEST!</a>";
    ?>
    

    so you append it, and then once you've got all your results in the $accounts string, you write it out to the file.

    0 讨论(0)
提交回复
热议问题