Jump to content


Photo

Searchscript - results returned?


  • Please log in to reply
2 replies to this topic

#1 Mr Chris

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

Posted 10 July 2006 - 11:17 AM

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'] – 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

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

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

Can anyone please help?

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


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 July 2006 - 11:35 AM

Where is the array $row coming from for these lines?
<?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'];
}?>

Ken

#3 Mr Chris

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

Posted 10 July 2006 - 12:03 PM

Hi Ken,

Whoops typo that should be $rows as defined:

while($rows = mysql_fetch_assoc($query))

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

Many Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users