2014-10-19 46 views
0

我有多個div,看起來像HTML下面。對於這些div中的每一個,我試圖通過名稱LI_Dept來獲取輸入值作爲數組。這些通過PHP發佈。PHP:顯示每個div的列表

如何獲取每個div的列表或輸入值,而不是顯示所有div的所有列表。如果這有道理?

問題是關於我的PHP代碼關於foreach($list as $li){},任何人有任何想法?

感謝

HTML

<div id="table_dept" class="count"> 
    <span class="dept_format"> 
    TEST 
    </span> 
    <input id="ID_Dept" name="ID_Dept[]" type="text" class="dept_textfields" value="1" maxlength="3"> 
    <span class="dept_format"> 
    TEST1 
    </span> 
    <input id="deptcode_Dept" name="DC_Dept[]" type="text" class="dept_textfields" value="2" maxlength="30"> 
    <span class="dept_format"> 
    TEST2 
    </span> 
    <input id="deptname_Dept" name="DN_Dept[]" type="text" class="dept_textfields" value="2" maxlength="50"> 
    <span class="dept_format"> 
    List: 
    </span> 
    <table width="100%"> 
    <thead> 
    </thead> 
    <tbody id="D_tbody"> 
     <tr> 
     </tr> 
     <tr> 
     </tr> 
     <tr> 
     </tr> 
     <tr> 
     <td> 
      <input id="list_Dept" name="LI_Dept[]" type="text" class="dept_li_textfields" value="List1" maxlength="50"> 
     </td> 
     </tr> 
     <tr> 
     <td> 
      <input id="list_Dept" name="LI_Dept[]" type="text" class="dept_li_textfields" value="List2" maxlength="50"> 
     </td> 
     </tr> 
     <tr> 
     <td> 
      <input id="list_Dept" name="LI_Dept[]" type="text" class="dept_li_textfields" value="List3" maxlength="50"> 
     </td> 
     </tr> 
     <tr> 
     <td> 
      <input id="list_Dept" name="LI_Dept[]" type="text" class="dept_li_textfields" value="List4" maxlength="50"> 
     </td> 
     </tr> 
     <tr> 
     <td> 
      <input id="list_Dept" name="LI_Dept[]" type="text" class="dept_li_textfields" value="List5" maxlength="50"> 
     </td> 
     </tr> 
    </tbody> 
    </table> 
</div> 

PHP:

for($i=0;$i < $rowcount;$i++) <---FOR EACH DIV 
{ 
    $dID = $_POST['ID_Dept']; 
    $dDCode = $_POST['DC_Dept']; 
    $dName = $_POST['DN_Dept']; 
    $list= $_POST['LI_Dept']; 

    foreach ($list as $li) { <-----I Need HELP to change this for EACH DIV RATHER THAN ALL... 
     $Acontent .= "\r\n".'<'.$element_LI.'>'.$li.'</'.$element_LI.'>'; 
    } 
} 

結果: 我現在的結果,不是我了。

<Department id="1"> 
<DeptCode>1</DeptCode> 
<DeptName>1</DeptName> 
<li>List1</li> 
<li>List2</li> 
<li>List3</li> 
<li>List4</li> 
<li>List5</li> 
<li>List6</li> 
<li>List7</li> 
<li>List8</li> 
<li>List9</li> 
<li>List10</li> 
<li>List11</li> 
<li>List12</li> 
<li>List13</li> 
<li>List14</li> 
<li>List15</li> 
<li>List16</li> 

<Department id="2"> 
<DeptCode>2</DeptCode> 
<DeptName>2</DeptName> 
<li>List1</li> 
<li>List2</li> 
<li>List3</li> 
<li>List4</li> 
<li>List5</li> 
<li>List6</li> 
<li>List7</li> 
<li>List8</li> 
<li>List9</li> 
<li>List10</li> 
<li>List11</li> 
<li>List12</li> 
<li>List13</li> 
<li>List14</li> 
<li>List15</li> 
<li>List16</li> 

<Department id="3"> 
<DeptCode>3</DeptCode> 
<DeptName>3</DeptName> 
<li>List1</li> 
<li>List2</li> 
<li>List3</li> 
<li>List4</li> 
<li>List5</li> 
<li>List6</li> 
<li>List7</li> 
<li>List8</li> 
<li>List9</li> 
<li>List10</li> 
<li>List11</li> 
<li>List12</li> 
<li>List13</li> 
<li>List14</li> 
<li>List15</li> 
<li>List16</li> 

要求 下面的結構是什麼,我想實現的,而不是上面,使用PHP。

<Department id="1"> 
<DeptCode>1</DeptCode> 
<DeptName>1</DeptName> 
<li>List1</li> 
<li>List2</li> 
<li>List3</li> 
<li>List4</li> 
<li>List5</li> 
<li>List6</li> 

<Department id="2"> 
<DeptCode>2</DeptCode> 
<DeptName>2</DeptName> 
<li>List7</li> 
<li>List8</li> 
<li>List9</li> 
<li>List10</li> 
<li>List11</li> 

<Department id="3"> 
<DeptCode>3</DeptCode> 
<DeptName>3</DeptName> 
<li>List12</li> 
<li>List13</li> 
<li>List14</li> 
<li>List15</li> 
<li>List16</li> 
+0

不要放棄明白你的問題,此代碼似乎做什麼你問'爲($ I = 0; $ I <$行數; $ I ++){ $ DID = $ _POST [ 'ID_Dept']; $ dDCode = $ _POST ['DC_Dept']; $ dName = $ _POST ['DN_Dept']; $ list = $ _POST ['LI_Dept']; } – Billy 2014-10-19 17:42:46

+0

什麼決定了你的列表如何分解?就像一個人有6個下拉,其他人有5個。什麼決定了這些休息? – Rasclatt 2014-10-19 17:59:08

+0

那就是我試圖找出在PHP中。我需要根據每個div來分解它們。看看我的要求,我試圖讓我的輸出看起來像需求而不是結果。如果這是有道理的。我想弄清楚如何使用PHP打破列表並將它們輸出爲ECHO或其他內容,而不是顯示所有的每個DIV標籤。 – AlpaxJ1 2014-10-20 17:28:40

回答

0
SELECT * FROM 
(
SELECT 
list1 as l1, list2 as l2, list3 as l3, list4 as l4, list5 as l5, list6 as l6, 1 AS selection 
WHERE x = y 

UNION ALL 

SELECT 
list7 as l1, list8 as l2, list9 as l3, list10 as l4, list11 as l5, list12 as l6, 2 AS selection 
WHERE x = y 
) 
as request 

$reponse->execute(); 

for($i=0;$data = $reponse->fetch();$i++) 
{ 
<Department id="<?php echo $data['selection'] ?>"> 
<DeptCode><?php echo $data['selection'] ?></DeptCode> 
<DeptName><?php echo $data['selection'] ?></DeptName> 
<li><?php echo $data['l1'] ?></li> 
<li><?php echo $data['l2'] ?></li> 
<li><?php echo $data['l3'] ?></li> 
<li><?php echo $data['l4'] ?></li> 
<li><?php echo $data['l5'] ?></li> 
<li><?php echo $data['l6'] ?></li> 

} 
+0

這不是什麼即時通訊,謝謝你給它一個去。 FOR EACH DIV: ECHO ID ECHO DEPTNAME DEPTCODE ECHO FOR EACH LIST(LI)INSIDE CURRENT DIV: ECHO列表。 不知道該PSUEDO CODE是否有助於解釋它... – AlpaxJ1 2014-10-20 17:49:27