0

这来自我的表单字段:

$subject="physics with maths";

这是在我的数据库中:

$keywordsindatabse="(physics && electronics) || (electronics & communication) || (electronics and communication)";

在提交表单时,我想将条件$keywordsindatabse$subject. 有任何想法吗?

任何帮助将不胜感激。

代码:

<form id="myform" name="myform">
<select name="sselect"  id="itmn">

                        <option value="">Select</option>

            <option value='1'>1</option>
                        <option value='2'>2</option>
                        <option value='3'>3</option>
                        <option value='4'>4</option>
                        <option value='5'>5</option>
                        <option value='6'>6</option>
                        <option value='7'>7</option>            
          </select>
<input  type='text' name='gmajorsub' id=""" value="" onblur="chkdegree(document.getElementById('itmn').value,this.value);">
</form>

<script>
 function chkdegree(item_id,keyword)
 {


 $.ajax({
            type: "GET",
            url: "degree_match.php",
            dataType: 'html',
        data: {item_id : item_id,keyword : keyword},
            success: function(data){
                if(data=="0")
        {
         alert("Dear Applicant, You are not allowed to register.You Subject not matching our essential qualification requirements.");
                  document.getElementById("gmajorsub").value="";
                  document.getElementById("gmajorsub").focus();
                  return false;
        }
            }
    });
 }

</script>

度匹配.php:

<?php
include("../../lib/dbc/dbConnection.php");
require('../../lib/dbc/commonFunc.php');
require('../../lib/dbc/dbHandler.class.php');
$dbObject = new dbHandler();
$dbObject->connect();
$query="select * from advt_110_post_details where recNo='".$_REQUEST['item_id']."'";
$result=mysql_query($query);
$num=mysql_fetch_array($result);
$keyword=strtolower($_REQUEST['keyword']);

$degree=$num['subject_keywords'];

$degree1=explode("|",$degree);





$max = array(null, 0); // category, occurences
/*foreach($degree1 as $k => $v) {
  $replaced = str_replace($v, '##########', $keyword);
  preg_match_all('/##########/i', $replaced, $matches);
  if(count($matches[0]) > $max[1]) {
    $max[0] = $k;
    $max[1] = count($matches[0]);
  }
}


if($max[1]>=count($degree1))
{
  echo"1";  
}
else{
    echo"0";
}
*/
/*foreach($degree1 as $k => $v) {

if ( strstr( $membership, "member" ) )
{

}

}
*/

?>
4

2 回答 2

0

注意:您的代码受 SQL 注入的影响。查看使用 PDO 准备语句或 mySQLi 准备语句。至少,将字符串输入包装到 mysql_real_escape_string 中的 hte 数据库中。


查看您的代码,您正在从数据库中获取项目,然后进行过滤。我假设 mySQL。

在数据库端这样做可能会更好。查看“全文搜索”。这仅适用于 MyISAM 表,因此如果需要,请更改它。然后在“subject_keywords”上的表中添加全文索引,您需要使用全文设置布尔搜索。布尔搜索的详细信息在这里

(否则,Rishi 上面的回答介绍了您需要的循环 - 您的尝试中缺少这些循环。)

于 2012-11-26T00:33:19.773 回答
-1

据我从您的帖子中了解到,以下代码可能会有所帮助..

$subject="physics with maths";
$keywordsindatabse="(physics && electronics) ||
(electronics & communication) ||
(electronics and communication)";
$pieces = explode(" ", $subject);
$piecesDB = explode("||", $keywordsindatabse);
$subsDBv=array();
foreach($piecesDB as $key=>$subsDB){
    $subsDBv[$key] = str_replace(array("(",")"),"",explode(" ", $subsDB));
    }
foreach($subsDBv as $subslvd){
foreach($subslvd as $subslv){
    $ao = next($subslvd);
foreach($pieces as $subs){
if((strpos($subslv,$subs) !== false) AND (strpos($ao,$subs) !== false)){
    echo "Match found..<br />"; 
    }
    else{       
        echo "Sorry, no match found..<br />";
        }
}
}
}
于 2012-11-23T06:17:57.163 回答