1 Replies - 263 Views - Last Post: 17 February 2012 - 05:32 AM Rate Topic: -----

#1 aristide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 25-December 11

[PHP] Create .TXT File Help

Posted 17 February 2012 - 04:51 AM

I have this code in PHP:
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database", $con);

$result = mysql_query("SELECT * FROM videos2");

while($row = mysql_fetch_array($result))
  {
  echo $row['ID'] . "- " . $row['URL'];
  echo "<br />";
  }

mysql_close($con);
?>


And until here, all is right, the code does what i want it to do, no problems. But i am using this for an app that can only bee feeded .txt files, so it causes a problem. i need a code that gets the displayed data and creates a new text file (links.txt) with the data exactly displayed as in links.php. the data displayed in links.php is like:

- google.com
- example.com


what code can i use? Thanks!

This post has been edited by Atli: 17 February 2012 - 05:26 AM
Reason for edit:: Don't post links to sites with malicous content!


Is This A Good Question/Topic? 0
  • +

Replies To: [PHP] Create .TXT File Help

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3044
  • View blog
  • Posts: 4,556
  • Joined: 08-June 10

Re: [PHP] Create .TXT File Help

Posted 17 February 2012 - 05:32 AM

View Postaristide, on 17 February 2012 - 11:51 AM, said:

what code can i use?

What have you tried? We won't just write the code you need for you. Show us what you've tried so far and we'll tell you how to proceed from there. - Keep in mind that all you need to create a text file is to create the contents of the text file as a string and then use the file_put_contents function to save it to a file.


Also, if all you need from your database is the ID and URL fields, then tell the database that when you query for you data. You should always avoid using the wild-card character (*) in SELECT queries. (Unless you have a very good reason for it.)
/* Instead of doing this */
SELECT * FROM videos2

/* Do this */
SELECT ID, URL FROM videos2


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1