View Single Post
Old 05-14-2012, 11:47 AM  
roly
Confirmed User
 
Join Date: Aug 2002
Posts: 1,844
Quote:
Originally Posted by Brujah View Post
Code:
$sql = "select foo from bar where catid = $cat limit 20";
$result = mysql_query($sql ,$db);

$scriptoutput = '';
while ($myrow = mysql_fetch_array($result))
{
    $scriptoutput .= '<li>' . $myrow['something'];
}

$myfile= fopen ("/home/domains/domain.com/public_html/mytxt.txt", "w+");
fwrite($myfile, $scriptoutput);
fclose($myfile;
If you're interested in using prepared statements, you can do this:
Code:
$mysqli = new mysql( 'localhost', 'username', 'password', 'db' );

$content = '';
if( $stmt = $mysqli->prepare("SELECT foo FROM bar WHERE catid = ? LIMIT 20") ) 
{
  $stmt->bind_param( 'i', $cat );
  $stmt->execute();
  $stmt->bind_result( $foo );
  while ( $stmt->fetch() )
  {
    $content .= '<li>' . $foo;
  }
  $stmt->close();
}

$mysqli->close();

file_put_contents( '/path/to/saved.txt', $content );
set up a cron to execute this every 24 hours
0 3 * * * /usr/bin/php /path/to/cron.php
Thanks Brujah, that's a big help, very much appreciated.
roly is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote