Jump to content


Photo

Problems with Search.


  • Please log in to reply
5 replies to this topic

#1 Mr Chris

Mr Chris
  • Members
  • PipPipPip
  • Advanced Member
  • 336 posts

Posted 15 July 2006 - 10:23 AM

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_stories

Now say my search returned 3 results:

-   One Business Story
-   One Sports Story
-   One News Story

I 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 returned

IE 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):

<?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 ======== */ 
?>

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 news link that I clicked on it would go to:
http://www.mysite.com/search/news/story.php?story_id

So if It was a sport link that I clicked on it would go to:
http://www.mysite.com/search/sport/story.php?story_id

So if It was a business link that I clicked on it would go to:
http://www.mysite.com/search/business/story.php?story_id

So it’s completely ignoring my IF rules and I can’t see why…

Many Thanks

Chris

#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 July 2006 - 10:27 AM

So what is it outputting then?

#3 Mr Chris

Mr Chris
  • Members
  • PipPipPip
  • Advanced Member
  • 336 posts

Posted 15 July 2006 - 10:38 AM

Just the pathname of where the current file is.  If you take a look at:

http://www.slougheaz...&Submit2=Submit

and hover over more it just returns:

http://www.slougheaz...ew_site/search/

When as it's a sport story it *should* look in the if conditions and output...

http://www.slougheaz...ew_site/search/sport/story.php?story_id=thestoryidnumber

See what I mean?

Many Thanks


#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 July 2006 - 10:40 AM

Well it seems as if it isn't getting the section from the database, try echoing it out:
$section = $row['section'];
echo "Section: $section";

#5 Mr Chris

Mr Chris
  • Members
  • PipPipPip
  • Advanced Member
  • 336 posts

Posted 15 July 2006 - 10:58 AM

That was it!  It now works:

echo $section;

Should have been:

  echo $rows['section'];

Thank you for your advise.

#6 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 July 2006 - 11:09 AM

Excellent, its quite often pesky typing mistakes!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users