Mr Chris Posted July 15, 2006 Share Posted July 15, 2006 Hi, Still having problems with my searchscript.Let me explain a bit further as I still am not getting it to work properly and would like some more help if possible please.Have a searchscript which seaches for stories in one table cms_storiesNow say my search returned 3 results:- One Business Story- One Sports Story- One News StoryI want the <href> of the story to output to go to:…/sport/story.php?story_id='.$row['story_id'] – For Sport results returned…/business/story.php?story_id='.$row['story_id'] – For Business results returned…/news/story.php?story_id='.$row['story_id'] – For News results returnedIE going to different folders depending on the section ie the nature of the story returned in the search – be it a news/sport or business (which are defined as section in the db):[code=php:0]<?php include("../**********");// Define Variable form 'First Query' post; $section = $_GET['section']; $searchstring = ($_GET['searchstring'] != "") ? $_GET['searchstring'] : false; if($searchstring === false){ die("No searchstring was entered!"); }$query=mysql_query("select *, DATE_FORMAT(appeared, '%W %e %M %Y') as formatted_date from cms_stories where section like '%$section%' AND ( headline LIKE '%$searchstring%' OR body_text LIKE '%$searchstring%' )") or die(mysql_error()); echo "<table width=\"100%\" border=0 bgcolor=\"#cccccc\" cellpadding=1 cellspacing=1>\n"; echo "<tr> <th><DIV ALIGN=\"LEFT\">Type of Story</div></th> <th><DIV ALIGN=\"LEFT\">Appeared in Newspaper</div></th> <th><DIV ALIGN=\"LEFT\">Headline</div></th> <th><DIV ALIGN=\"LEFT\">Read Story</div></th> </tr>"; while($rows = mysql_fetch_assoc($query)) { $section = $row['section']; $story_id = (int)$_GET['story_id']; if ($section == 'news') { $filetype = "../news/story.php?story_id=" . $rows['story_id']; } else if ($section == 'sport') { $filetype = "../sport/story.php?story_id=" . $rows['story_id']; } else if ($section == 'business') { $filetype = "../business/story.php?story_id=" . $rows['story_id']; } echo "<tr BGCOLOR=\"#FFFFFF\"><td>"; echo $section; echo "</td><td>"; echo $rows['formatted_date']; echo "</td><td>"; echo $rows['headline']; echo "</td><td>"; echo '<a href="' . $filetype . '">[ more ]</a>'; echo "</td></tr>"; } echo "</table>"; echo "</table>"; /* ======== END FIRST FORM SEARCH ======== */ ?>[/code]Now I’ve tried to do this, but it does not seem to work. It just output's the path of the current directory the search page resides when you click on the more link:http://www.mysite.com/search/But I want it to go to a folder and get the story_id name depending on the nature of the story:So if It was a [b]news[/b] link that I clicked on it would go to:http://www.mysite.com/search/[b]news/story.php?story_id[/b]So if It was a [b]sport[/b] link that I clicked on it would go to:http://www.mysite.com/search/[b]sport/story.php?story_id[/b]So if It was a [b]business[/b] link that I clicked on it would go to:http://www.mysite.com/search/[b]business/story.php?story_id[/b]So it’s completely ignoring my IF rules and I can’t see why…Many ThanksChris Quote Link to comment https://forums.phpfreaks.com/topic/14665-problems-with-search/ Share on other sites More sharing options...
GingerRobot Posted July 15, 2006 Share Posted July 15, 2006 So what is it outputting then? Quote Link to comment https://forums.phpfreaks.com/topic/14665-problems-with-search/#findComment-58461 Share on other sites More sharing options...
Mr Chris Posted July 15, 2006 Author Share Posted July 15, 2006 Just the pathname of where the current file is. If you take a look at:http://www.slougheaz.org/greenock/new_site/search/results.php?section=sport&searchstring=ads&Submit2=Submitand hover over more it just returns:http://www.slougheaz.org/greenock/new_site/search/When as it's a sport story it *should* look in the if conditions and output...http://www.slougheaz.org/greenock/new_site/search/[b]sport/story.php?story_id=thestoryidnumber[/b]See what I mean?Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/14665-problems-with-search/#findComment-58463 Share on other sites More sharing options...
GingerRobot Posted July 15, 2006 Share Posted July 15, 2006 Well it seems as if it isn't getting the section from the database, try echoing it out:$section = $row['section'];echo "Section: $section"; Quote Link to comment https://forums.phpfreaks.com/topic/14665-problems-with-search/#findComment-58465 Share on other sites More sharing options...
Mr Chris Posted July 15, 2006 Author Share Posted July 15, 2006 That was it! It now works:echo $section;Should have been: echo $rows['section']; Thank you for your advise. Quote Link to comment https://forums.phpfreaks.com/topic/14665-problems-with-search/#findComment-58466 Share on other sites More sharing options...
GingerRobot Posted July 15, 2006 Share Posted July 15, 2006 Excellent, its quite often pesky typing mistakes! Quote Link to comment https://forums.phpfreaks.com/topic/14665-problems-with-search/#findComment-58469 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.