The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Flat File Database
Discuss Flat File Database in the PHP Development forum on Dev Shed. Flat File Database PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 11th, 2000, 06:34 AM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Hi,
I am new to php and I am looking for a flat file database system which will allow me to call different product prices from the flat file database. So basically I have a page that lists many different products. For each product I want to list the price. So I would do a search for each individual product code and then return the appropriate price. Can this be done? And can someone point me in the right direction because I don't even know where to start. I first tried doing this using cgi and some ssi's. However due to multiple ssi's on one page (for mutiple prices) it was too slow and so I was recommended to use php. I would be very grateful to someone who can help me. Please note, the only functionality i really need is for the text file to be searched on and to be able to return a price or code value. Thanks in advance.
Dave.
|

April 12th, 2000, 06:41 PM
|
|
Contributing User
|
|
Join Date: Apr 2000
Posts: 31
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
It would be really much easier to help you if I knew the format of your "flat file database". If this really is a text file rather than a real database I would suggest you'd move on to mysql or similar if you only can. And if you can't paste some records from that file so we can help you.
|

April 12th, 2000, 11:36 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Ok, well I can't really move to mySql for lack of support. However i can use any delimeted type database (eg , or ; or | etc). The fields would be like...
Product_Code, Product, Price, Supplier. I want to be able to search on the product code and display the price. Do you think this is possible??? Thanks heaps for your help.
Dave
|

April 12th, 2000, 11:42 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
I am also not sure what other databases I can use but I am open to suggestions (but not solutions such as msql, mysql etc as I believe they are not supported on my server and that they would be overkill anyway). I am not sure if DBM would be a suitable type solution but I am still unsure how to implement a system using this as well. Thanks again.
Dave
|

April 13th, 2000, 12:14 PM
|
 |
Contributing User
|
|
|
|
I'm also new to PHP, but have had some
success using flat files. You might want
to give something like this a try:
<?php
$fileName = "yourDataFile"; //The flat file
//name goes here
$myFile = fopen("$fileName","r");
if(!($myFile)) {
print("Couldn't read $fileNamen");
}
while(!feof($myFile)) {
$myLine = chop(fgets($myFile, 255));
//Use as many $var's as you have fields.
//Also, this example is 'pipe' delimited.
list( $var1, $var2 )=split("[|]", $myFile);
//Put your evaluation code here...
//ie. if($var == what I'm looking for) {
// print("some HTML");
// }
}
fclose($myFile);
?>
Hope this helps. 
Like I said though, I'm new to PHP so this
may not be the most efficent code...
Scott
|

April 13th, 2000, 06:27 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
I tried this code but couldn't get it working  Does this code allow me to use multiple search type items on the one page? I need at least say 20 or so. I was thinking the top part where it opens the file could be at the top, say in the head tag. Then whenever I need to pull in code use the find and print bit. Would that work? Also, are you able to send me an example page you have used as I tried the one you sent and couldn't get it working. Thanks for your help.
Dave
|

April 13th, 2000, 09:30 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Ok, well I have something finally working due to some help from WDN. However because I want to seek multiple items on the one page I want them to be displayed in the order that I want them, not the order that they appear in the database. However I am having trouble using the rewind command. I cannot get it to work properly. Here is what I have so far. Can someone please suggest where to put the code to rewind to the start of the file so that I get the results in the order that I seek for them. Thanks in advance...
-------------------
<?php
$myFile = fopen("hardware.txt","r");
while(!feof($myFile)) {
$myLine = chop(fgets($myFile, 255));
list( $code, $product, $price, $street, $supplier ) = split("[|]", $myLine);
?>
</head>
<p>
<?php
if($code=="GREEN12") {
print("<font size='2' face='Arial, Helvetica'>");
print("Code: <b>$code</b><br>n");
print("Street Price: $<b>$street</b><br></font>n");
}
if($code=="TURBO02") {
print("<font size='2' face='Arial, Helvetica'>");
print("Code: <b>$code</b><br>n");
print("Street Price: $<b>$street</b><br></font>n");
}
if($code=="GREEN05") {
print("<font size='2' face='Arial, Helvetica'>");
print("Code: <b>$code</b><br>n");
print("Street Price: $<b>$street</b><br></font>n");
}
?>
<?php
}
fclose($myFile);
?>
|

April 13th, 2000, 11:22 PM
|
 |
Contributing User
|
|
|
|
I see a potential problem with your code,
and have a suggestion as well.
First, the problem.
You're adding a </head> and <p> tag every
time you go through the loop. That could
result in some rather odd looking output.
Now, the suggestion.
You can check for multiple matches in one
"if".
if($code=="GREEN12" | | $code=="TURBO02") {
print("some HTML..."n);
}
You can get some pretty complex evaluations
just using | | and && (or and and).
As for using the rewind function, I've never
had a use it (in the week or so I've been
thrashing about with PHP  )
Good Luck,
Scott
|

April 13th, 2000, 11:41 PM
|
|
Junior Member
|
|
Join Date: Apr 2000
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
well the idea was to have this code inside my existing page. So i would have a beginning <head> tag etc. Also it wouldn't be going through a loop. It would only go through once. Perhaps if I show you a page that will demonstrate how I want to lay it out. This page I was able to link the prices using cgi but you will notice it is very slow to load. The cgi brings in the prices that are in bold. I merely call the code of the product I want and make it return the price. This is the same type of thing i want to do with my php. Here is the page... http://www.microway.com.au/catalog/listcpp_addons1.stm
As for the suggestion about using the | and & I don't think it would help me much as i will know which product to call in so I just will search on that and return the price. And I will want several, each below its respective description.
thanks again.
dave
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|