我想检查用户的专业知识并显示他们的网络图。我想使用LIKE的原因是因为在mysql数据库中,其工作场所还包含了专有技术属性。例如:Petronas的数据分析师。因此,我想检查他们的专业知识是否是数据分析师,并显示他们的网络图。
这是我尝试过的代码:
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$sql = "SELECT * FROM professional, job, location WHERE PROFESSIONAL_ID LIKE '%$id%' AND PROFESSIONAL_ID=JOB_ID AND JOB_ID = LOCATION_ID " ;
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
echo "
<div class='card'>
<img src='../images/img.png' style='width:100%'>
<h2>".$row['PROFESSIONAL_NAME']."</h2>
<p class='title'><i class='fa fa-briefcase' aria-hidden='true'></i> ".$row['JOB_NAME']."</p>
<p class='marker'><i class='fa fa-map-marker' aria-hidden='true'></i> ".$row['LOCATION_NAME']."</p>
<a href=".$row['PROFESSIONAL_URL']."><p><button>Contact</button></p></a>
</div>
<div class='network'>
<h2> Filter Network</h2>
</div>
<div class='filter'>
<input type='radio' value='Expertise' unchecked name='radioBtn' onclick='checkexpertise(".$row['JOB_NAME'].")'> <label> Expertise</label><br>
<input type='radio' value='Location' unchecked name='radioBtn' onclick='checklocation(".$row['LOCATION_NAME'].")'> <label> Location</label><br>
<input type='radio' value='Workplace' unchecked name='radioBtn' onclick='checkworkplace()'> <label> Workplace </label><br>
<input type='radio' value='Past Workplace' unchecked name='radioBtn' onclick='checkpast()'> <label>Past Workplace</label><br>
</div>";
}
?>
<script>
function CheckExpertise (Expertise) {
if Expertise LIKE %Data Analyst% OR %data analyst%
{
window.location.replace("expertise.html");
}
}
</script>
答案 0 :(得分:0)
您可以使用includes
,我建议将字符串转换为所有小写字母,然后再进行检查,因此您只需要进行一次检查即可。
function CheckExpertise (Expertise) {
if (Expertise.toLowerCase.includes("data analyst") {
window.location.replace("expertise.html");
}
}
答案 1 :(得分:0)
您可以为此使用正则表达式:
if (/.*data analyst.*/i.test(Expertise)) {
window.location.replace("expertise.html");
}
但是请看一下mysqli准备好的语句和输出清理(例如使用htmlentities)。用户可以将任何内容发送为“ id”,包括您可能不想执行的精巧SQL查询;)
$id = $_GET['id'];
$query = mysqli_prepare($conn, "SELECT * FROM professional, job, location WHERE PROFESSIONAL_ID LIKE ? AND PROFESSIONAL_ID=JOB_ID AND JOB_ID = LOCATION_ID " ;
mysqli_bind_param($query, "s", "%{$id}%");
mysqli_stmt_execute($query);
$result = mysqli_stmt_get_result($query);