2012-01-27 12 views
-3

私はPHPで次のことを達成しようとしています。 in between配列に値が存在し、終了して次の配列値で再起動する場合

<?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の値が含まれています。値がすでに存在する場合は、 の代わりに次のコードを実行する必要があります。スクリプトは、最初にもう一度開始し、次に2番目の値 の配列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

+2

あなたはこれまでにどのようなコードを書いていますか? – Crontab

+1

私はあなたがしようとしていることを本当に理解していません。例を挙げていただけますか? – JJJ

答えて

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

私は近いと思います。更新された質問をもう一度読んでください:) –

0
foreach ($acs_id as $item) { 

    if ($item == $acs_exist) continue; 

    // continue with the script (query etc) 

} 

これはあなたのものですか?後で?

+0

私はあなたも近いと思います。更新された質問を再読してください:) –

+0

@MaartenHartman '$ acs_id'と配列ですか? 'print_r()'を表示できますか?また、 '$ add_total'と' $ done_total'には何が入っていますか? – DaveRandom

関連する問題