朋友们,我不管可能与否,无论如何我想要对具有相同喜好名称的用户进行分组(mysql'喜欢'功能)
[0]=>
array(5) {
["id"]=>"21"
["user_id"]=>"58"
["preference_id"]=>"4"
["sub_preference_id"]=>"7"
["preference_name"]=>"stephens collage"
}
[1]=>
array(5) {
["id"]=>"22"
["user_id"]=>"52"
["preference_id"]=>"4"
["sub_preference_id"]=>"1"
["preference_name"]=>"st stephens"
}
[2]=>
array(5) {
["id"]=>"25"
["user_id"]=>"61"
["preference_id"]=>"4"
["sub_preference_id"]=>"9"
["preference_name"]=>"joseph"
}
表示我希望输出如下:
1]斯蒂芬斯拼贴画,圣斯蒂芬斯
2]约瑟夫
我试过这段代码:
$school_preference ="SELECT * FROM gic_user_preference where preference_id='4'";
$result_school_preference = mysqli_query($createCon->connect(), $school_preference);
$school = array();
while ($show_school_preference = mysqli_fetch_assoc($result_school_preference)) {
$school_preference = $show_school_preference['sub_preference_id'];
$get_all_school_preference =mysqli_query($createCon->connect(),"SELECT gic_user_preference.id,gic_user_preference.user_id,gic_user_preference.preference_id,gic_user_preference.sub_preference_id,gic_user_wise_school_preference.preference_name FROM gic_user_preference INNER JOIN gic_user_wise_school_preference ON gic_user_preference.sub_preference_id = gic_user_wise_school_preference.id where gic_user_preference.sub_preference_id='$school_preference'");
while ($schools = mysqli_fetch_assoc($get_all_school_preference)) {
$school[$schools['preference_name']][] = $schools;
}
}
它提供输出
array(4) {
["stephens collage"]=>
array(1) {
[0]=>
array(5) {
["id"]=>
string(2) "21"
["user_id"]=>
string(2) "58"
["preference_id"]=>
string(1) "4"
["sub_preference_id"]=>
string(1) "7"
["preference_name"]=>
string(16) "stephens collage"
}
}
["st stephens"]=>
array(1) {
[0]=>
array(5) {
["id"]=>
string(2) "22"
["user_id"]=>
string(2) "52"
["preference_id"]=>
string(1) "4"
["sub_preference_id"]=>
string(1) "1"
["preference_name"]=>
string(11) "st stephens"
}
}
["joseph"]=>
array(1) {
[0]=>
array(5) {
["id"]=>
string(2) "25"
["user_id"]=>
string(2) "61"
["preference_id"]=>
string(1) "4"
["sub_preference_id"]=>
string(1) "9"
["preference_name"]=>
string(6) "joseph"
}
}
}
任何想法如何将这些数据分组为像函数一样的mysqli ......
答案 0 :(得分:-1)
我认为您可以使用正则表达式匹配来查找相同的名称!