2015-09-26 52 views
2

這裏是我的代碼添加多個類型到表。我想結合區域,位置,類型並將它們一次添加到表格中。我認爲這只是不會工作if(!empty($_POST['types'] && $_POST[''] && $_POST[''])謝謝!合併多個POST並將其添加到表

if(!empty($_POST['types'])) { 
    $values = array(); 
    foreach($_POST['types'] as $typ_id) { 
     $values[] = sprintf('(%d, %d)', $station_id, $typ_id); 
    } 

    $query = 'INSERT IGNORE INTO station_typ_tab 
      (station_id, typ_id, area_id, location_id) 
      VALUES ' . 
      implode(',', $values); 
      mysql_query($query, $db) or die(mysql_error($db)); 
    } 

編輯:這裏是類型的代碼部分[]和同樣是區域和位置

<td>Types:<br/> <small>CTRL + click to set multiple pollutants</em></small> 
    </td> 
    <td> 
    <?php 
    $query = 'SELECT typ_id, typ FROM typ_tab ORDER BY typ ASC'; 
    $result = mysql_query($query, $db) or die(mysql_error($db)); 

    if (mysql_num_rows($result) > 0) { 
     echo '<select multiple name="types[]">'; 
     while ($row = mysql_fetch_array($result)) { 
      if (isset($station_typ[$row['typ_id']])) { 
       echo '<option value="' . $row['typ_id'] . '" 
       selected="selected">'; 
       } else { 
        echo '<option value="' . $row['typ_id'] .'">'; 
       } 
       echo $row['typ'] . '</option>'; 
      } 
      echo '</selected>'; 
     } else { 
      echo '<p><strong>Databaza je prazdna... <a href="edit_pollutant.php">Enter database</a></strong></p>'; 
     } 
     mysql_free_result($result); 

如何結合的類型,位置和麪積$ _POST如果他們來自不同的選擇輸入。像if(!empty($_POST['types'] && $_POST['areas'] && $_POST['location'])){ $values = array(); foreach(NEW VARIABLE as $typ_id && area_id &&location_id) { $values[] = sprintf('(%d, %d, %d, %d)', $station_id, $typ_id, area_id, location_id);如果有可能做這樣

+0

是什麼$ _ POST [「類型」]的價值? – rocky

+0

你的問題是什麼? –

+0

如何結合$ _POST類型,位置和區域,如果它們來自不同的選擇輸入。類似於'if(!empty($ _ POST ['types'] && $ _POST ['areas'] && $ _POST ['location'])){ $ values = array(); foreach(NEW VARIABLE as $ typ_id && area_id && location_id){ $ values [] = sprintf('(%d,%d,%d,%d)',$ station_id,$ typ_id,area_id,location_id);' 如果可以這樣做 – R2D2

回答

1

在IF結合嘗試使用

if((!empty($_POST['types'])) && (!empty($_POST['area'])) && (!$_POST['location']))); 
相關問題