Jump to content

search function keywords system error !


lofaifa

Recommended Posts

//get the search variable from the FORM

$function_keywords = mysql_real_escape_string($_POST['function_keywords']);

//trim whitespace from the stored variable

$trimmed = trim($function_keywords);

//separate key-phrases into keywords

$trimmed_keywords = explode(" ",$trimmed);

// Build SQL Query for each keyword entered

foreach ($trimmed_keywords as $trimm){

// MySQL "MATCH" is used for full-text searching.

//this code is ebv weird , should check out soon!

$query = "SELECT * ,

  MATCH (function_description) AGAINST ('".$trimm."') AS score

  FROM table_name

  WHERE MATCH (function_description) AGAINST ('+".$trimm."')

  ORDER BY score DESC

  ";

// Execute the query to  get number of rows that contain search kewords

$results=mysql_query ($query,$connection);

$row="";

$row =$row . mysql_fetch_array($results, MYSQL_BOTH);

}

$row_num=mysql_num_rows ($row);

if($row_num < 1){

    redirect("welcome.php?search=fail");

}

else if ($row_num > 1){ ?>

<html>

<head>

<title>Search results</title>

</head>

<body>

<?php

foreach($row as $row_result){

echo "function name : {$row_result['function_name']} --- function Description : {$row_result['function_description']}<br/><br/>";

}?>

</body>

</html>

 

IS there an error on the SQL syntax ? or its about ?  :

 

$results=mysql_query ($query,$connection);
$row="";
$row =$row . mysql_fetch_array($results, MYSQL_BOTH);
}
$row_num=mysql_num_rows ($row);

 

Link to comment
https://forums.phpfreaks.com/topic/252754-search-function-keywords-system-error/
Share on other sites

<?php require_once("includes/functions.php");?>
<?php
session_start();
if (isset($_SESSION["user_name"])) { 
require_once("includes/connection.php");
//get the search variable from the FORM
$function_keywords = mysql_real_escape_string($_POST['function_keywords']);
if($function_keywords=="" || empty($function_keywords)){
redirect("show.php?functions=PHP");
}
//trim whitespace from the stored variable
$trimmed = trim($function_keywords);
//separate key-phrases into keywords
$trimmed_keywords = explode(" ",$trimmed);
// Build SQL Query for each keyword entered
foreach ($trimmed_keywords as $trimm){
// MySQL "MATCH" is used for full-text searching.
//this code is ebv weird , should check out soon!
$query = "SELECT * FROM functions
	  WHERE function_description LIKE '{$trimm}' 	 
	  ";
// Execute the query to  get number of rows that contain search kewords
$results=mysql_query ($query,$connection);
if(!$results){
	redirect("errors/error_db.html");
}
$row="";
$row.=mysql_fetch_array($results, MYSQL_BOTH);
}
?>
<html>
<head>
<title>Search results</title>
</head>
<body>
<strong>Here are Your results :</strong> 
<?php 
foreach($row as $row_result ){
echo "function name : {$row_result['function_name']} --- function Description : {$row_result['function_description']}<br/><br/>";
}?>
</body>
</html>
<?php 
}
else {
	redirect("main.php?error=log");
}
?>

 

 

 

ERROR :

 

 

 

Here are Your results : 
Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\thinkgs\search.php on line 38

 $row="";
$row.=mysql_fetch_array($results, MYSQL_BOTH);

These two lines will make $row into a string that just says "Array"

 

 

 foreach($row as $row_result ){

WHen you give a string to foreach, it throws that error.

 

You want to use $results directly in your foreach:

foreach ( $results as $row ) {

 

Archived

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

×
×
  • 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.