Jump to content

Archived

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

Mr Chris

Searchscript - results returned?

Recommended Posts

Hi Guys,

Still having a few problems with this searhscript that I built

I have a searchform which searches on two things:

1) the ‘section’(nature) of a story ie news, sport, business etc
2) Any searchstring text entered in a text box

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'] – [B]For Sport results returned[/b]
…/business/story.php?story_id='.$row['story_id'] – [B]For Business results returned[/b]
…/news/story.php?story_id='.$row['story_id'] – [B]For News results returned[/b]

But for each story the search return just outputs all results as:

[b]../Resource  id  #3[/b] – just ignoring the if rules?

Can anyone please help?

[code=php:0]
<?php
/* ======== START FIRST FORM SEARCH ======== */

include("../****************");

// Define Variable form 'First Query' post;
$section = $_GET['section'];
$searchstring = ($_GET['searchstring'] != "") ? $_GET['searchstring'] : false;

if($searchstring === false){
die("No searchstring was entered!");
}

if ($section == 'news') {
    $link = "../news/story.php?story_id=" . $row['story_id'];
} else if ($storytype == 'sport') {
    $link = "../sport/story.php?story_id=" . $row['story_id'];
} else if ($storytype == 'business') {
    $link = "../business/story.php?story_id=" . $row['story_id'];
}

$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))
  {
  echo "<tr BGCOLOR=\"#FFFFFF\"><td>";
  echo $rows['section'];
  echo "</td><td>";
  echo $rows['formatted_date'];
  echo "</td><td>";
  echo $rows['headline'];
  echo "</td><td>";
  echo '<a href="' . $link . '">[ more ]</a>';
  echo "</td></tr>";
  }
echo "</table>";

/* ======== END FIRST FORM SEARCH ======== */
?>
[/code]

Share this post


Link to post
Share on other sites
Where is the array $row coming from for these lines?
[code]<?phpf ($section == 'news') {
    $link = "../news/story.php?story_id=" . $row['story_id'];
} else if ($storytype == 'sport') {
    $link = "../sport/story.php?story_id=" . $row['story_id'];
} else if ($storytype == 'business') {
    $link = "../business/story.php?story_id=" . $row['story_id'];
}?>[/code]

Ken

Share this post


Link to post
Share on other sites
Hi Ken,

Whoops typo that should be $row[b]s[/b] as defined:

[code]while($rows = mysql_fetch_assoc($query))
[/code]

..But still does this strange resource id message???

Many Thanks

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.