I am working on a PHP search system but for some reason it isn't working. <!-- Put Code Before Results To Appear --> <div align="center"> <form action="search.php" method="post"> Search Term: <input type="text" name="search" /> | Sort By: <select name="sort_type"><option>Old to New</option><option value="new_first">New to Old</option><option value="atoz">A to Z</option></select> </form> </div> <?php echo "Searcher"; ?> <?php $search_term = $_POST['search']; $sort = $_POST['sort_type']; $count = '0'; while($while !== 'false') { if(file_exists('news/' . $count . 'htm')) { } else { $while = 'false'; } $file_complete = file_get_contents('news/' . $count . '.htm'); $title = explode('dc:title="',$file_complete); $title = explode('"',$title[1]); $title = $title[0]; $picture = 'images/' . $count . '.jpg'; $description = explode('<div class="tweetmeme_button" style="float: right; margin-left: 10px;">',$file_complete); $description = explode('<p>',$description[2]); $description = explode('</p>',$descryption[1]); $description = $description[0]; $match = 0; $st_description = str_replace($search_term,$search_term,$description,$match); if($match>0) { $description = substr($description,0,25); $news_array .= '<table cellspacing="10" cellpadding="10" style="width:50%;" align="center"><tr><td><img src="' . $picture . '" alt="Thumbnail" /></td>'; $news_array .= '<td><div align="center"><b>' . $title . '</b></div><br /><br /><p style="text-indent:20px;">' . $description . '</p></td></tr></table><br /><br />?%?%\\'; $count++; } else { } } $show_news = explode('?%?%\\',$news_array); if($sort == 'new_first') { array_reverse($show_news); } elseif($sort == 'atoz') { sort($show_news); } else { } $returned_results = count($show_news); echo '<br /><br /><div align="center"><b>' . $returned_results . '</b> Results Returned!'; echo 'Your Search Term ' . $search . '. To reutn more results try limiting your search terms'; foreach($show_news as $item) { echo $item; } ?> <!-- Put Code After Search Results to Appear --> Code (markup): It pulls news files from the news directory with 1.htm 2.htm etc. as the news files and then displays information on them based on your search term. It just shows blank though.
You should change this if(file_exists('news/' . $count . 'htm')) { } else { $while = 'false'; } Code (markup): to be like this if(!file_exists('news/' . $count . 'htm')) { break; } Code (markup):
<!-- Put Code Before Results To Appear --> <div align="center"> <form action="search.php" method="post"> Search Term: <input type="text" name="search" /> | Sort By: <select name="sort_type"><option>Old to New</option><option value="new_first">New to Old</option><option value="atoz">A to Z</option></select> <input type="submit" value="Search" /> </form> </div> <?php $search_term = $_POST['search']; $sort = $_POST['sort_type']; $news_array = ''; $count = 1; $while = 'true'; while($while !== 'false') { if(!file_exists('news/' . $count . 'htm')) { break; } else { } $file_complete = file_get_contents('news/' . $count . '.htm'); $title = explode('<div id="Layer-text" class="textcontent" ><h2>',$file_complete); $title = explode('</h2>',$title[1]); $title = $title[0]; $picture = 'images/' . $count . '.jpg'; $description = explode('<SPACER TYPE=BLOCK HEIGHT=0 WIDTH=245 ALIGN=LEFT><a href="#" > Comments</a><hr><br><p><br><p></font>',$file_complete); $description = explode('</div></div></div>',$description[1]); $description = $description[0]; $match = 0; $st_description = str_replace($search_term,$search_term,$description,$match); if($match>0) { $description = substr($description,0,25); $news_array .= '<table cellspacing="10" cellpadding="10" style="width:50%;" align="center" border="1"><tr><td><img src="' . $picture . '" alt="Thumbnail" /></td><td><div align="center"><b>' . $title . '</b></div><br /><br /><p style="text-indent:20px;">' . $description . '</p></td></tr></table><br /><br />?%?%\\'; echo $news_array; $count++; } else { $count++; } } $show_news = explode('?%?%\\',$news_array); if($sort == 'new_first') { array_reverse($show_news); } elseif($sort == 'atoz') { sort($show_news); } else { } $returned_results = count($show_news); echo '<br /><br /><div align="center"><b>' . $returned_results . '</b> Results Returned!'; foreach($show_news as $item) { echo $item; } ?> <!-- Put Code After Search Results to Appear --> Code (markup): For some reason it doesn't display anything. Here is news file it is getting its information from http://macme.org/new/news/1.htm others will be set up in the same format. Here is where the script will appear http://macme.org/new/search.php. I really don't see why it wouldn't display anything even just the blank table. I just made it echo $news_array just to see if I had an error past that part in time. Also thanks but that break thing didn't work.