Hallo,
weiß jemand wie ich eine Datenbankabfrage aus einem Script in eine .txt Datei speichern kann ?
Gruß
Emtec
weiß jemand wie ich eine Datenbankabfrage aus einem Script in eine .txt Datei speichern kann ?
Gruß
Emtec
<?php
if ($fp = fopen('targetfile.txt', 'w'))
{
$res = mysql_query('SELECT entry FROM table ORDER BY entry') or die(mysql_error());
while ($row = mysql_fetch_assoc($res))
{
fwrite($fp, $row['entry']);
}
fclose($fp);
}
?>
<?PHP
require('./includes/config.inc.php');
header("Content-Type: text/plain");
$domain = $HTTP_HOST;
$url = $SITE_URL;
$ci = 0;
$q_array = split("( |%20)",$q);
while (list($key, $unit) = each($q_array)) {
if ($ci == 0) {
$qu = "'%".$unit."%'";
} else {
$qu = $qu." and title like '%".$unit."%'";
}
$ci++;
}
/* get auction data */
$query = "select * from auctions where ends >= now() + 0 and title like $qu";
$result = mysql_query($query);
if ( !$result )
{
echo mysql_errno(). ": ".mysql_error(). "\n";
exit;
}
for($im=0; $im<mysql_num_rows($result); $im++) {
$title = mysql_result ( $result, $im, "title" );
$id = mysql_result ( $result, $im, "id" );
$date = mysql_result ( $result, $im, "starts" );
$category = mysql_result ( $result, $im, "category" );
$minimum_bid = mysql_result ( $result, $im, "minimum_bid" );
$ends = mysql_result ( $result, $im, "ends" );
$current_bid = mysql_result ( $result, $im, "current_bid" );
if ($current_bid == 0) { $current_bid = $minimum_bid; }
/* Get number of bids */
$query = "select * from bids where auction=\"$id\"";
$result_numbids = mysql_query ( $query );
if (!$result_numbids)
{
echo mysql_errno(). ": ".mysql_error(). "\n";
} else {
$num_bids = mysql_num_rows ( $result_numbids );
}
// mysql_free_result($result_numbids);
$year = intval ( date("Y"));
$month = intval ( date("m"));
$day = intval ( date("d"));
$hours = intval ( date("H"));
$minutes = intval ( date("i"));
$seconds = intval ( date("s"));
$ends_year = substr ( $ends, 0, 4 );
$ends_month = substr ( $ends, 4, 2 );
$ends_day = substr ( $ends, 6, 2 );
$ends_hours = substr ( $ends, 8, 2 );
$ends_minutes = substr ( $ends, 10, 2 );
$ends_seconds = substr ( $ends, 12, 2 );
$Tpl_date = "$ends_year-$ends_month-$ends_day $ends_hours:$ends_minutes:$ends_seconds";
/* Get Catagory Title */
$c_name[] = array();
$c_id[] = array();
$cat = "";
$query = "select cat_id,parent_id,cat_name from categories where cat_id='$category'";
$result_kat = mysql_query($query);
if (!$result_kat)
{
echo mysql_errno(). ": ".mysql_error(). "\n";
}
$result_cat = mysql_fetch_array ($result_kat);
$parent_id = $result_cat[parent_id];
$cat_id = $categories;
$j = $category;
$i = 0;
//$cat = $result_cat[cat_name];
mysql_free_result($result_kat);
do {
$query = "select cat_id,parent_id,cat_name from categories where cat_id='$j'";
$result_kat = mysql_query($query);
if ( $result_kat )
{
$result_cat = mysql_fetch_array ( $result_kat );
$parent_id = $result_cat[parent_id];
$c_name[$i] = $result_cat[cat_name];
$c_id[$i] = $result_cat[cat_id];
$i++;
$j = $parent_id;
mysql_free_result($result_kat);
}
} while ( $parent_id != 0 );
for ($j=$i-1; $j>=0; $j--)
{
if ( $j == 0) {
$cat .= $c_name[$j];
} else {
$cat .= $c_name[$j].":";
}
}
$current_bid = number_format($current_bid,2);
print ("$Tpl_date|$id|".$url."item.php?id=$id|$title|$cat|$current_bid|$num_bids|$currency\n");
} // For $im
?>
EDIT:
[php]-tags by Abraxax
print ("$Tpl_date|$id|".$url."item.php?id=$id|$title|$cat|$current_bid|$num_bids|$currency\n");
print ($Tpl_date.'|'.$id.'|'.$url.'item.php?id='.$id.'|'.$title.'|'.
$cat.'|'.$current_bid.'|'.$num_bids.'|'.$currency."\n");
fwrite ($fp, $Tpl_date.'|'.$id.'|'.$url.'item.php?id='.$id.'|'.$title.'|'.
$cat.'|'.$current_bid.'|'.$num_bids.'|'.$currency."\n");
Kommentar