Jump to content

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 ) {

 

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.