현재 Wordpress (최신 버전)의 플러그인에서 작업하고 있습니다. 이제 GravityForms에 연결하면이 모든 것을 제외하고는 모든 것이 잘되었습니다.
array(3) {
[0]=>
array(3) {
["text"]=>
string(9) "Service 1"
["value"]=>
string(1) "1"
["isSelected"]=>
bool(false)
}
[1]=>
array(4) {
["text"]=>
string(9) "Service 2"
["value"]=>
string(1) "2"
["isSelected"]=>
bool(false)
["price"]=>
string(0) ""
}
[2]=>
array(4) {
["text"]=>
string(9) "Service 3"
["value"]=>
string(1) "3"
["isSelected"]=>
bool(false)
["price"]=>
string(0) ""
}
}
올바른지 foreach 루프가 다시 나에게 행을 준다 처음 :
function DbUpdateServices($services){
$choices = $services->choices;
print_r($choices);
global $wpdb;
$allValues = array();
foreach($choices as $choice){
$text = $choice["text"];
$value = $choice["value"];
$allValues[] = $value;
$name_exists = $wpdb->get_results("SELECT * FROM quotation_diensten WHERE dienstNaam='$text'", ARRAY_A);
echo("SELECT * FROM quotation_diensten WHERE dienstNaam='".$text."'");
if($wpdb->num_rows == 0){
$value_exists = $wpdb->get_results("SELECT * FROM quotation_diensten WHERE dienstValue = $value", ARRAY_A);
if($wpdb->num_rows == 0){
echo "No rows found";
$wpdb->insert('quotation_diensten',
array(
"dienstNaam" => $text,
"dienstValue" => $value
),
array('%s','%d')
);
} else {
echo "Row found";
$wpdb->update("quotation_diensten",
array(
"dienstNaam" => $text
),
array("dienstValue"=> $value
),
array("%s")
);
}
} else {
echo "($value,$text) Bestaat,<br>";
$wpdb->update("quotation_diensten",
array(
"dienstValue" => $value
),
array("dienstNaam"=> $text
),
array("%d")
);
}
$wpdb->flush();
echo "<hr>";
//delete
$allServices = $wpdb->get_results("SELECT * FROM quotation_diensten", ARRAY_A);
foreach ($allServices as $service) {
if(!in_array($service["dienstValue"], $allValues)){
//verwijderen
$wpdb->delete("quotation_dienstaanvraag", array('dienstenID'=>$service["dienstenID"]));
$wpdb->delete("quotation_bedrijfsdiensten", array('dienstenID'=>$service["dienstenID"]));
$wpdb->delete("quotation_diensten", array('dienstenID'=>$service["dienstenID"]));
}
}
}
}
이 $choices
의 내용은 다음과 같습니다
여기 내 코드입니다.
두 번째와 세 번째는 0
행입니다.
dienstenID | dienstNaam | dienstValue
221 Service 1 | 1
351 | Service 2 | 2
352 | Service 3 | 3
나와 내 동료가 이유를 알아낼 수 :
이 내 데이터베이스 구조입니다. 여기서 뭐가 잘못 됐니? 모든 다음 줄의
'$ name_exists = $ wpdb-> 준비 ("quotation_diensten SELECT * FROM WHERE dienstNaam이 = '% s'이 (가)", $ 텍스트를); 은 두 번째 요청시 여전히 0 행을 반환합니다. – Emiel
작은 따옴표를 삭제해야합니다. – Blackbam
'$ name_exists = $ wpdb-> prepare ("SELECT * FROM quotation_diensten where dienstNaam = % s", $ text); ' – Blackbam