Jump to content

Archived

This topic is now archived and is closed to further replies.

Mr Chris

Problems with Search.

Recommended Posts

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

[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 Thanks

Chris

Share this post


Link to post
Share on other sites
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=Submit

and 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

Share this post


Link to post
Share on other sites
Well it seems as if it isn't getting the section from the database, try echoing it out:
$section = $row['section'];
echo "Section: $section";

Share this post


Link to post
Share on other sites
That was it!  It now works:

echo $section;

Should have been:

  echo $rows['section'];

Thank you for your advise.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.