dagger2002
Programmer
Ok everyone I have a problem and have no idea how to solve it. I normally just use mySQL to do my db's but for this project we are useing mySQL for intitial storage of data then we are doing a little data manipulateing and storeing part of the data into a flat file DB. I have the code for what I am doing to get the data to the flat file but am not sure how to be able to use the data after I get it into the file.
So here is the code.
It gets the information from the db array and stores it here.
This is the db set of instructions:
Thanks All in advance
So here is the code.
Code:
<?php
$id = $row2[stat_id];
$date = $row2[stat_date];
$time = $row2[stat_time];
$ip = $row2[stat_ip];
$page = $row2[stat_page];
$title = $row2[stat_title];
$file = 'stats.db';
?>
<?php
// Opens File for write which erases file if it already exists
$fp = fopen($file, "w");
// $fp = fopen("data.txt","a");
// Writes to file
fwrite($fp, $id . " &|& " . $date . " &|& " . $time . " &|& " . $ip . " &|& " . $page . " &|& " . $title . "\n");
// Closes file
fclose($fp);
?>
It gets the information from the db array and stores it here.
This is the db set of instructions:
Code:
$query = "SELECT * FROM stats_it WHERE `stat_ip` NOT LIKE '1ST IP GOES HERE' ORDER BY stat_id ASC";
$result = mysql_query($query) or die/*(mysql_error());*/("Error with the submission.");
$numRows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$dropTmp = "DROP TABLE temp_Stats";
$dropRes = mysql_query($dropTmp) or die(mysql_error());//("Error with the submission.");
$queryTmp = "CREATE TABLE temp_Stats ( `stat_id` int(4) NOT NULL , `stat_date` varchar(10) NOT NULL default '', `stat_time` varchar(8) NOT NULL default '', `stat_ip` varchar(15) NOT NULL default '', `stat_page` varchar(255) NOT NULL , PRIMARY KEY (`stat_id`))";
$resultTmp = mysql_query($queryTmp) or die(mysql_error());//("Error with the submission.");
// Inserts data into Temp Table
$queryInsTmp = "REPLACE INTO temp_Stats SET stat_id=\"$row[stat_id]\", stat_date=\"$row[stat_date]\", stat_time=\"$row[stat_time]\", stat_ip=\"$row[stat_ip]\", stat_page=\"$row[stat_page]\"";
$resultInsTmp = mysql_query($queryInsTmp) or die(mysql_error());//("Error with the submission.");
while($row = mysql_fetch_array($result)){
$queryInsTmp = "REPLACE INTO temp_Stats SET stat_id=\"$row[stat_id]\", stat_date=\"$row[stat_date]\", stat_time=\"$row[stat_time]\", stat_ip=\"$row[stat_ip]\", stat_page=\"$row[stat_page]\"";
$resultInsTmp = mysql_query($queryInsTmp) or die(mysql_error());//("Error with the submission.");
}
//SELECT * FROM TempTable";
//echo '<h1>' . $numRows . '</h1>';
$query2 = "SELECT * FROM temp_stats WHERE `stat_ip` NOT LIKE '2ND IP GOES HERE' ORDER BY stat_id ASC";
$result2 = mysql_query($query2) or die/*(mysql_error());*/("Error with the submission.");
$numRows2 = mysql_num_rows($result2);
$row2 = mysql_fetch_array($result2);
// Opens File for write which erases file if it already exists
$file = 'stats.db';
$fp = fopen($file, "w");
echo "<h3>" . $numRows . "<h3>";
echo "<h4>" . $numRows2 . "<h4>";
$id = $row2[stat_id];
$date = $row2[stat_date];
$time = $row2[stat_time];
$ip = $row2[stat_ip];
$page = $row2[stat_page];
$title = $row2[stat_title];
// Writes to file
fwrite($fp, $id . " &|& " . $date . " &|& " . $time . " &|& " . $ip . " &|& " . $page . " &|& " . $i . "\n");
$i++;
while($row2 = mysql_fetch_array($result2)){
// echo $row2[stat_ip] . '<br />';
$id = $row2[stat_id];
$date = $row2[stat_date];
$time = $row2[stat_time];
$ip = $row2[stat_ip];
$page = $row2[stat_page];
$title = $row2[stat_title];
$file = 'stats.db';
// Writes to file
fwrite($fp, $id . " &|& " . $date . " &|& " . $time . " &|& " . $ip . " &|& " . $page . " &|& " . $title . "\n");
echo $i . '<br />';
$i++;
}
// Closes file
fclose($fp);
echo $i;
mysql_close($link);
?>
Thanks All in advance