fleabel Posted June 14, 2006 Share Posted June 14, 2006 I have a flat file database containing various sporting events. I want to be able to have a simple search with a drop down menu containing, for example, a list of states. So that the person would select the state they want events from and then it would just display anything from that state not the whole file. Does that make sense? I could just use a different file for each state but then they might want to search by type of sport or month of the year so i don't want to have everything stored in two or three different files, one is much less effort. Please note: a mySQL or some such database is not an option in my particular situation.I haven't been able to find anything on the vastness of the web that explains how to do this or if it is even possible. Thank you in advance your help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/ Share on other sites More sharing options...
Monkeymatt Posted June 14, 2006 Share Posted June 14, 2006 How is this flatfile database configured -- what do the rows look like? Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45327 Share on other sites More sharing options...
fleabel Posted June 14, 2006 Author Share Posted June 14, 2006 Here's a sample:[code]17th|June|2006|NRL|Sharks vs. Sea Eagles|Toyota Park|Sydney|NSW18th|June|2006|NRL|Bulldogs vs. Cowboys|Carrara Stadium|Gold Coast|QLD18th|June|2006|NRL|Storm vs. Raiders|Olympic Park|Melbourne|VIC16th|June|2006|AFL|St. Kilda vs. Adelaide|Telstra Dome|Melbourne|VIC17th|June|2006|Rugby Union|Cook Cup - Qantas Wallabies v England|Telstra Dome|Melbourne|VIC17th|June|2006|AFL|Fremantle vs. Geelong|Subiaco|Perth|WA17th|June|2006|AFL|Brisbane Lions vs. Western Bulldogs|Gabba|Brisbane|QLD17th|June|2006|AFL|Port Adelaide vs. West Coast|AMMI Stadium|Adelaide|SA18th|June|2006|AFL|Essendon vs. Melbourne|Telstra Dome|Melbourne|VIC23rd|June|2006|NRL|Storm vs. Bulldogs|Olympic Park|Melbourne|VIC24th|June|2006|NRL|Knights vs. Sharks|Energy Australia Stadium|Newcastle|NSW[/code]That is:Date|Month|Year|Sport|Event|Venue|City|StateAt a later date I would also like to have events added the file via a form, but that's for another day [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45328 Share on other sites More sharing options...
poirot Posted June 14, 2006 Share Posted June 14, 2006 [code]<?php// Let's say $str = the sample you posted$tmp_array = explode("\n", $str);$data = array();foreach ($tmp_array as $value) { $data[] = explode("|", $value);}echo '<pre>';print_r($data);echo '</pre>';?>[/code]Should print:[code]Array( [0] => Array ( [0] => 17th [1] => June [2] => 2006 [3] => NRL [4] => Sharks vs. Sea Eagles [5] => Toyota Park [6] => Sydney [7] => NSW ) [1] => Array ( [0] => 18th [1] => June [2] => 2006 [3] => NRL [4] => Bulldogs vs. Cowboys [5] => Carrara Stadium [6] => Gold Coast [7] => QLD ) [2] => Array ( [0] => 18th [1] => June [2] => 2006 [3] => NRL [4] => Storm vs. Raiders [5] => Olympic Park [6] => Melbourne [7] => VIC ) [3] => Array ( [0] => 16th [1] => June [2] => 2006 [3] => AFL [4] => St. Kilda vs. Adelaide [5] => Telstra Dome [6] => Melbourne [7] => VIC ) [4] => Array ( [0] => 17th [1] => June [2] => 2006 [3] => Rugby Union [4] => Cook Cup - Qantas Wallabies v England [5] => Telstra Dome [6] => Melbourne [7] => VIC ) [5] => Array ( [0] => 17th [1] => June [2] => 2006 [3] => AFL [4] => Fremantle vs. Geelong [5] => Subiaco [6] => Perth [7] => WA ) [6] => Array ( [0] => 17th [1] => June [2] => 2006 [3] => AFL [4] => Brisbane Lions vs. Western Bulldogs [5] => Gabba [6] => Brisbane [7] => QLD ) [7] => Array ( [0] => 17th [1] => June [2] => 2006 [3] => AFL [4] => Port Adelaide vs. West Coast [5] => AMMI Stadium [6] => Adelaide [7] => SA ) [8] => Array ( [0] => 18th [1] => June [2] => 2006 [3] => AFL [4] => Essendon vs. Melbourne [5] => Telstra Dome [6] => Melbourne [7] => VIC ) [9] => Array ( [0] => 23rd [1] => June [2] => 2006 [3] => NRL [4] => Storm vs. Bulldogs [5] => Olympic Park [6] => Melbourne [7] => VIC ) [10] => Array ( [0] => 24th [1] => June [2] => 2006 [3] => NRL [4] => Knights vs. Sharks [5] => Energy Australia Stadium [6] => Newcastle [7] => NSW ))[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45332 Share on other sites More sharing options...
fleabel Posted June 14, 2006 Author Share Posted June 14, 2006 Sorry i'm a bit thick. Can you please elaborate on how I would use that. Thanks [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45344 Share on other sites More sharing options...
Monkeymatt Posted June 14, 2006 Share Posted June 14, 2006 Here's a way to search for state:[code]<?php// Let's say $str = the sample you posted// And $state is the state you want to search for$tmp_array = explode("\n", $str);foreach ($tmp_array as $value) { $curr = explode("|", $value); // check for whatever you want here if ($curr[7] == $state) { // print it out however you like echo "<pre>"; print_r($curr); echo "</pre>"; }}?>[/code]You could simply extend that to search for other things.Monkeymatt Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45346 Share on other sites More sharing options...
fleabel Posted June 14, 2006 Author Share Posted June 14, 2006 This is driving me nuts. Everything works except the if statement can somebody please have a look and tell me what i'm doing wrong. If I comment out the if statement and just have it print every line from the file it is fine but as soon as i try to get it to check for something i can't get it work.[code]<html><body><table border="1" cellpadding="3"><tr bgcolor="#CCCCCC"> <td>Date</td> <td>Month</td> <td>Year</td> <td>Sport</td> <td>Event</td> <td>Venue</td> <td>City</td> <td>State</td></tr><?php $fp = 'events_database.txt'; $tmp_array = file($fp);$state = 'VIC';foreach ($tmp_array as $value) { $curr = explode("|", $value); // check for whatever you want here if($curr[7] == $state){ // print it out however you like echo ' <tr> <td>'.$curr[0].'</td> <td>'.$curr[1].'</td> <td>'.$curr[2].'</td> <td>'.$curr[3].'</td> <td>'.$curr[4].'</td> <td>'.$curr[5].'</td> <td>'.$curr[6].'</td> <td>'.$curr[7].'</td> </tr>'; }}?> </table></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45395 Share on other sites More sharing options...
poirot Posted June 14, 2006 Share Posted June 14, 2006 Add:var_dump($curr[7]);Inside the loop. This will tell you what $curr[7] actually is.My guess is that $curr[7] will have some empty character (space, newline), and this causes the comparison to fail.If this is the case, use trim($curr[7]) == $state. Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45531 Share on other sites More sharing options...
fleabel Posted June 15, 2006 Author Share Posted June 15, 2006 Hallelujah it works!Sorry i'm a bit thick sometimes [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11942-solved-searching-displaying-from-flat-files-please-help/#findComment-45764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.