Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-29-2005, 08:48 PM Query a flat file?
Experienced Talker

Posts: 34
Trades: 0
I found a link to a tutorial for working with flat file databases on this forum. That's how I developed the code I have below... The code opens and displays all the records in a flatfile database, separated by tabs.

Now: Is there any way to have the PHP display only records that fulfill certain criteria...For example, what if I want to display only records whose $field1 variable (Column one) contains the text "Webmaster Talk"....Or something like that...?

Code:
$fp = fopen('stock.txt','r');
if (!$fp) {echo 'ERROR: Unable to open file. Email Andrew with the exact contents of this error, and this error ID: 05-29-2005-One-Fifty-Five</table></body></html>'; exit;}

while (!feof($fp)) {
$line = fgets($fp, 1024); //use 2048 if very long lines
list ($field1, $field2, $field3, $field4, $field5) = split ('	', $line);
$fp++;
echo '
<tr>
<td>'.$field1.'</td>
<td>'.$field2.'</td>
<td>'.$field3.'</td>
<td>'.$field4.'</td>
<td>'.$field5.'</td>
<td>'.$field6.'</td>
</tr>';
}
 
fclose($fp);
Thanks,

Andrew
mtairhead is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-30-2005, 03:15 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You will have to either read lines in cycle and compare each of them or read the whole file into memory and sort it out in there. If a file is not very large (under 200K for example) and rarely updated, then it won't hurt a lot, but on large amounts of data which is changed or added frequently it is strongly recommended to use MySQL. If you already ask about queries then in not-too-far future you will need more flexibility with your queries, thus you will have to reinvent the bicycle.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-30-2005, 07:49 AM
Experienced Talker

Posts: 34
Trades: 0
The info is updated often, which is why I use a flatfile. I haven't found anyone who can tell me how to have a computer automatically update a MySQL database. The process must be streamlined, and it must be automated, as this information is upated 1-2 times a day.

As I cannot find a solution for this problem, it seems that I am the star crossed lover of the flatfile. I can use the software I downloaded recently, which is designed to automatically upload files on a scheduled basis. Using that, in union with an Access database, which updates the data on a scheduled basis, and exports it into a tab-separated file, I'll be able to automate the entire process.

The flatfile is about 104KB...If it grows, I can split it into several flatfiles.

If anyone has a suggestion as to how to update a MySQL database automatically, (I need to have no part of it...The computer I put to this task shouldn't even have to have a monitor) please let me know. The data I would be updating with is already automatically generated....And I use GoDaddy, which features MyPhPAdmin.

Thanks,

Andrew

Last edited by mtairhead; 05-30-2005 at 07:53 AM..
mtairhead is offline
Reply With Quote
View Public Profile
 
Old 05-30-2005, 07:54 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
You can write a php/perl/whatever script and schedule it on your server with cron so it starts on specified time, grabs remote server and does your mysql updates. Or you may schedule your local program so that it sends the file to your script which parses it and inserts into mysql. I didn't think it's such a problem to synchronize data.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-30-2005, 08:51 AM
Experienced Talker

Posts: 34
Trades: 0
lol...Where were you a week ago...? Thanks. So I can schedule a php script? On my server? (As you can tell, I haven't been at this much)

While I Google this concept, do you have any links or something that might be helpful to me in this project?

Thanks very much. You've made my day.

Andrew
mtairhead is offline
Reply With Quote
View Public Profile
 
Old 05-31-2005, 04:08 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
If you have unix-like OS on your server then you should use crontab for sheduling your script.
1. Login to your server via telnet or ssh
2. Type <b>pico mytasks</b> - this will start pico editor, usually it is installed on most unix-like systems
3. Type <b>0 0,12 * * * php /path/to/your/script.php &</b>
4. Press Ctrl-O, Ctrl-X (write out, close the editor)
5. Type <b>crontab mytasks</b>

Explained:
crontab command format has following fields:
- minute (0-59)
- hour (0-23)
- day of month (1-31)
- month of year (1-12)
- day of week (0-6, 0 is the sunday)
- next field is optional, it means the user who will run the task (I omitted it in my example)
- command field
In my example your script will start at 0:00 and 12:00 every day. Read more here about crontab: http://www.computerhope.com/unix/ucrontab.htm
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Query a flat file?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17072 seconds with 12 queries