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