【发布时间】:2018-05-12 13:07:37
【问题描述】:
我在mysql数据库中有律师,律师徽章,徽章表。我想将徽章中的所有徽章ID加载到一个数组中。(allBadges [])。我想将律师的所有徽章ID加载到另一个数组(lawyerBadges[])。然后我想检查一下allBadges元素是否在lawyerBades中。怎么做。
这是我到目前为止的代码。
$username = $_SESSION['username'];
getPoints();
function getPoints(){
global $connection;
global $username;
$pointCount_query =mysqli_query( $connection,"SELECT * FROM lawyer WHERE username='".$username."'");
$pointCount=mysqli_fetch_array($pointCount_query);
$points= (int)$pointCount['points'];
addBadges($points);
}
function addBadges($user_points){
global $connection;
global $username;
$badge_array = array();
$badgeList=mysqli_query($connection,"SELECT bId FROM badge ");
$badges=mysqli_fetch_array($badgeList);
$lawyers_badges=mysqli_query($connection,"SELECT bID FROM lawyerbadge WHERE username='".$username."'");
while($row=mysqli_fetch_assoc($lawyers_badges)){
$badge_array[]=$row;
}
//this is the problem area
foreach( $badge_array as $value){
echo $value.'<br />';
}
}
【问题讨论】: