Jump to content

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]
Link to comment
https://forums.phpfreaks.com/topic/14163-searchscript-results-returned/
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
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.