2012-01-27 21 views
-3

整整一天,我一直在努力實現與PHP下與下一個數組值重啓:如果存在數組,終值和

更新:這是我使用的代碼,請閱讀郵件在

之間
<?php 

    include ('acs_params.php'); 

    $acs_value_based = array(25, 30, 35, 40, 45, 50, 60, 70); 
    $acs_types = array("$add_total","$done_total"); 

     print_r($acs_id); 

    foreach ($acs_value_based as &$value) { 
    foreach ($acs_types as &$counters) { 

    if ($counters >= $value) {  

    if ($acs_types[0] == $counters) {$acs_types1 = '1'; $acs_name = 'Tasker'; $acs_action = 'adding';} 
    if ($acs_types[1] == $counters) {$acs_types1 = '2'; $acs_name = 'Completer'; $acs_action = 'completing';} 

    if ($value == '25') { $acs_lvl = '1'; $acs_id = '25';} 
    if ($value == '30') { $acs_lvl = '2'; $acs_id = '30';} 
    if ($value == '35') { $acs_lvl = '3'; $acs_id = '35';} 

    $acs_exists = $acs_types1 . $acs_id; 

在這裏應該檢查這個數組的print_r($ ACS_ID);包含值爲 $ acs_exists。如果該值已經存在,則不應該執行以下代碼,而應該在開始時重新開始該腳本,但應使用第二個值 數組print_r($ acs_id);.它的價值尚不存在,然後繼續查詢。 (我希望我的目標很明確)。

mysql_query("INSERT INTO users_log(id, log, userid, date, points, action) VALUES 

(id, 'achievement 1', '$username', '$currenttime', '0', '8') "); 

    mysql_query("INSERT INTO users_achievements(id, userid, acs_id, date) VALUES 

(id, '$username', '$acs_types1$acs_id', '$currenttime') "); 

    ?> 
+2

「重新啓動腳本」? – knittl 2012-01-27 16:53:51

+2

到目前爲止你寫了什麼代碼? – Crontab 2012-01-27 16:54:58

+1

我真的不明白你在做什麼。你能舉個例子嗎? – JJJ 2012-01-27 16:55:19

回答

0

這聽起來很簡單,但我給它一個鏡頭:

// if $acs_exist is not in the array $acs_id, execute script, otherwise do nothing 
if(!in_array($acs_exist, $acs_id)) { 
    // do whatever you want 
} 

我仍然在這裏暗戳...

foreach($acs_id => $id) { 
    if($acs_id == $acs_exist) { // already exists 
    } else { // does not exist yet, insert into db 
    // your code: INSERT INTO table (column, …) VALUES(:acs_id, …) 
    } 
} 
+0

我認爲你很接近,請重新閱讀更新的問題:) – 2012-01-27 17:38:31

0
foreach ($acs_id as $item) { 

    if ($item == $acs_exist) continue; 

    // continue with the script (query etc) 

} 

這就是你所說的,重新過後?

+0

我認爲你也接近了,請重新閱讀更新的問題:) – 2012-01-27 17:38:52

+0

@MaartenHartman是'$ acs_id'和數組?你可以顯示它的print_r()嗎?另外,'$ add_total'和'$ done_total'包含什麼? – DaveRandom 2012-01-27 17:43:06

相關問題