這是從我的表單字段來:匹配我的表單字符串與數據庫中的條件在PHP?
$subject="physics with maths";
這是在我的數據庫:
$keywordsindatabse="(physics && electronics) || (electronics & communication) || (electronics and communication)";
在提交表單我想與$subject
符合條件$keywordsindatabse
。 任何想法?
任何幫助將不勝感激。
代碼:
<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>
degree_match.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"))
{
}
}
*/
?>
你能微塵具體一點嗎?你想要什麼,你想要什麼(實際的代碼會有幫助) –
我已經提供了我的代碼.. –