Jump to content

[SOLVED] Please Help on a Search Engine


alexguz79

Recommended Posts

hey everybody..

 

trying to have this code working but allways give error on line 23-25 after the search, can anybody help me?

 

Code:

-----------------------------------------------------------------------------------------

<?

if (isset($keywords) && $keywords != "") {

 

      $searchterms = $_GET["keywords"];

 

      $query = "select * from perfect where match(nombre,texto) against('".mysql_real_escape_string($searchterms)."')";

      $result = mysql_query($query);

 

      if ($row = mysql_fetch_array($result)) {

 

              print"<br /><b>Your search returned ".mysql_num_rows($result)." results.</b>";

 

              $i = 1;

 

              do {

 

                    print"<br /><br />This is search result number {$i}";

 

                    $i++;

 

              { while ($row = mysql_fetch_array($result));

 

      } else {

 

              print"<br />Your search returned no results."

 

      } else {

 

      include('picture_search.php');

}

?>

-----------------------------------------------------------------------

Link to comment
Share on other sites

this is the error i get after the search is made:

 

Parse error: syntax error, unexpected T_ELSE in /home/mytrende/public_html/p_search.php on line 23

 

and the code is like this:

 

<?

if (isset($keywords) && $keywords != "") {

 

      $searchterms = $_GET["keywords"];

 

      $query = "select * from perfect where match(nombre_evento,texto_evento) against('".mysql_real_escape_string($searchterms)."')";

      $result = mysql_query($query);

 

      if ($row = mysql_fetch_array($result)) {

 

              print"<br /><b>Your search returned ".mysql_num_rows($result)." results.</b>";

 

              $i = 1;

 

              do {

 

                    print"<br /><br />This is search result number {$i}";

 

                    $i++;

 

              { while ($row = mysql_fetch_array($result));

 

      } else {

 

              print"<br />Your search returned no results."

 

      } else {

 

      include('picture_search.php');

}

?>

Link to comment
Share on other sites

On closer inspection of the code, you have some errors with your closing braces. You should really learn to format your code more cleanly.

 

Here is your cleaned up code with the closing braces fixed.

<?php
if (isset($keywords) && $keywords != "") {
$searchterms = $_GET["keywords"];

$query = "SELECT * FROM perfect WHERE MATCH(nombre,texto) AGAINST('".mysql_real_escape_string($searchterms)."')";
$result = mysql_query($query);

if ($row = mysql_fetch_array($result)) {
	print "Your search returned ".mysql_num_rows($result)." results.";
	$i = 1;
	do {
		print "This is search result number {$i}";
		$i++;
	} while ($row = mysql_fetch_array($result));
}
else
{
	print "Your search returned no results."
}
}
else
{
include('picture_search.php');
}
?>

 

If this is not the correct logic, I'm sorry, but it was hard to tell what statements went with which opening if statement.

Link to comment
Share on other sites

thanks for trying to help... the code from charlieholder looks cleaner... but have the same error....

 

Parse error: syntax error, unexpected '}' in /home/mytrende/public_html/p_search.php on line 19

 

if anybody knows from a good search tutorial link... so i can check what i;m doing wrong

Link to comment
Share on other sites

Here:

 

<?
if (isset($keywords) && $keywords != "") {
$searchterms = $_GET["keywords"];
$query = "select * from perfect where match(nombre_evento,texto_evento) against('".mysql_real_escape_string($searchterms)."')";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)) {
	print"Your search returned ".mysql_num_rows($result)." results.";
	$i = 1;
	do {
		print"This is search result number {$i}";
		$i++;
		} while ($row = mysql_fetch_array($result));
} else {
	print"Your search returned no results.";
}
} else {
include('picture_search.php');
}
?>

 

You were missing a trailing ; for print"Your search returned no results.";

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.