두 개의 배열이 있는데 두 배열 사이에 일치가 있는지 확인한 다음 둘 다 일치하는 경우 데이터베이스에 yes를 삽입합니다. 배열 중 하나는 정적 인 다른 요소와 비교하기 위해 한 번에 3 개의 요소를 사용합니다.배열의 일치하는 문자열 PHP
코드의 문제점은 대다수를 정확하게 비교하고 있지만 데이터베이스를 자세히 살펴 본 점입니다. 몇 가지 비교가 잘못되었습니다. 아무 것도 잘못 비교되지 않도록 내 코드를 구성하는 더 좋은 방법이 있습니까?
$ team_squad에서 서로 옆에있는 두 요소가 모두 '예'라고 가정하면 오류가 발생합니다.
문자열도 도전적으로 정확합니다. 여기
코드
<php
//Take 3 subs at a time 3 home and 3 away players
for($subs = 3;$subs<=$count_subs;$subs+=3){
//Set the answers for each player to 'no' (the for loop sets all players to no).
for($data=0; $data<$squad_length; $data++){
$input[$data] = 'no';
}
//Select 3 subs home and away for each team, starting from 0 and restrict to 3 and move up by 3's.
$h_subs_name = array_slice($home_subs_name,$subs-3, $subs);
$a_subs_name = array_slice($away_subs_name,$subs-3, $subs);
//Identify the matches from the players in the team squad with the subs
$subshome = array_intersect($team_squad, $h_subs_name);
$subsaway = array_intersect($team_squad, $a_subs_name);
//if array is not empty run code
if(!empty($subshome)){
//For each match in the change the 'no' to a 'yes' from the forloop.
foreach ($subshome as $key => $value) {
# code...
//Select the index to change to a yes
$input[$key] = $y;
}
}
//if array is not empty run code
if(!empty($subsaway)){
//For each match in the change the 'no' to a 'yes' from the forloop.
foreach ($subsaway as $k => $eachplayer) {
# code...
//Select the index to change to a yes
$input[$k] = $y;
}
}
foreach ($input as $s) {
$inserttablesub[] = '"'. $s . '"';
}
$querysub = 'INSERT INTO '.$subtable.' '.'('. implode(',', $players_name_insert).') '.'VALUES'.'(' . implode(',', $inserttablesub) . ')';
mysql_query($querysub)
or die(mysql_error());
unset($subshome);
unset($subsaway);
unset($input);
unset($inserttablesub);
}
?>
team_squad의 간단한 버전입니다 $team_squad
및 $a_subs_name
사용할 수
아니요, 데이터베이스의 각 셀에 예 또는 아니요를 삽입하려고합니다. 단 하나의 요소를 검색하지 않습니다 – user3210416