2016-03-02 37 views
1

我有多個rights例如。例如,1,2,3,4,5shows_id1,2,3,4,5,6,7,8,9MySQL中1NF中的表格格式php

我想在1NF

插入記錄在我的表如果用戶選擇rights4,5shows_id1,2,5,9 那麼我的表應該如下:

OUTPUT:

 | rights    |shows_id 
     --+----------------------+-------- 
     | 4     | 1 
     | 4     | 2 
     | 4     | 5 
     | 4     | 9 
     | 5     | 1   
     | 5     | 2 
     | 5     | 5 
     | 5     | 9 

     $right  = $_POST['rights']; 
     $get_movie = $_POST['shows']; 

     foreach($right as $row){ 
     $aryInsertVals = array ('id' => '' , 

      'rights'   => $row[implode(',',$rights)], 
      'shows_id'  => $row[implode(',',$get_movie)], 
      ); } 

但這隻會輸入重複的權利...我想要權利和shows_id

+0

這太寬泛了。你試過什麼了? – Ceeee

+0

yes..added my code – piyuu

+0

將代碼添加到問題中。 –

回答

0

將主鍵設爲兩列的組合。因此它不允許你插入重複的行。

如果有兩個表權限和顯示。

你想要兩張表中的笛卡爾積。這是通過從兩個表中選擇而沒有任何附加連接條件來實現的:

mysql> SELECT * FROM rights, showsId; 

Output : | rights    |shows_id 
     --+----------------------+-------- 
     | 4     | 1 
     | 4     | 2 
     | 4     | 5 
     | 4     | 9 
     | 5     | 1   
     | 5     | 2 
     | 5     | 5 
     | 5     | 9 

希望你只是在尋找這個。

+0

你可以建議在mysql中插入查詢 – piyuu

+0

我想插入我的記錄在db @ user3205932 – piyuu

+0

那麼問題是什麼。將主鍵組合爲兩列。因此它不允許你插入重複的行。 – FallAndLearn