MxGucci Posted November 12, 2008 Share Posted November 12, 2008 Below is the code which I am using to read information from a flat file database, the script below functions properly (..index.php?site=1 .. brings up the first line in my flat file database and so forth).. <?php $fileArray = file('flat-file-data.txt'); $site = $_GET['site'] - 1; // minus 1 to account for array index. if (isset($fileArray[$site])) { list ($field1, $field2, $field3, $field4, $field5, $field6) = split ('\|', $fileArray[$site]); echo ' <table border="0"> <tr> <td>'.$field1.'</td> <td>'.$field2.'</td> <td>'.$field3.'</td> <td>'.$field4.'</td> <td>'.$field5.'</td> <td>'.$field6.'</td> </tr></table>'; }else { echo 'That line does not exist'; } ?> My question is, is there any possible way to amend the above script so I can retrieve information line by line but by directing my visitors to a text link such as (..index.php?site=pokerstars) instead of having (..index.php?site=1), could someone assist me in doing this? I want to be able to define my own site name on each line, could we do this by storing a field that will contain the site name I want to use, and the script will some how read that line and direct my visitors to read from the line? I am so sorry for making this question so confusing, I hope one of you helpful php guru's might help out a lost soul. Thanks, Gucci Link to comment https://forums.phpfreaks.com/topic/132366-solved-read-from-flat-file-query-string-help/ Share on other sites More sharing options...
foxtrotwhiskey Posted November 12, 2008 Share Posted November 12, 2008 Hi Gucci, You can try adding a field, say at the beginning of each line for the site name and then scan each line for a match. Its pretty simple to do, see below: <?php $fileArray = file('flat-file-data.txt'); $sitename = $_GET['site']; $found = false; foreach ($fileArray as $line) { list ($cur_sitename, $field1, $field2, $field3, $field4, $field5, $field6) = split ('\|', $line); if ($cur_sitename == $sitename) //Check the site name { echo ' <table border="0"> <tr> <td>'.$field1.'</td> <td>'.$field2.'</td> <td>'.$field3.'</td> <td>'.$field4.'</td> <td>'.$field5.'</td> <td>'.$field6.'</td> </tr></table>'; $found = true; break; //break out of the foreach } } if (!$found) echo 'That line does not exist'; ?> Link to comment https://forums.phpfreaks.com/topic/132366-solved-read-from-flat-file-query-string-help/#findComment-688236 Share on other sites More sharing options...
MxGucci Posted November 12, 2008 Author Share Posted November 12, 2008 THANK YOU SIR! Link to comment https://forums.phpfreaks.com/topic/132366-solved-read-from-flat-file-query-string-help/#findComment-688237 Share on other sites More sharing options...
foxtrotwhiskey Posted November 12, 2008 Share Posted November 12, 2008 sorry, I accidentally prematurely posted that reply the first time, so you probably saw an incomplete message. Check it again for the whole thing. Link to comment https://forums.phpfreaks.com/topic/132366-solved-read-from-flat-file-query-string-help/#findComment-688240 Share on other sites More sharing options...
MxGucci Posted November 12, 2008 Author Share Posted November 12, 2008 its okay, it works now.. thanks so much sir. Link to comment https://forums.phpfreaks.com/topic/132366-solved-read-from-flat-file-query-string-help/#findComment-688246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.