Jump to content

Problems with Search.


Mr Chris

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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.