2013-04-01 66 views
1

我用一個名爲smarty的模板php系統很容易做到這一點。我目前無法Smarty的,所以我必須做手工,但我已經完全忘記了如何以及什麼是可能的....把php數組放入html代碼

   <? foreach ($searchresults as $row) { ?> 
        <tr class="tableRows"> 
         <td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td> 
         <td><a href="#"><? echo $row[0]; ?></a></td> 
         <td><? echo $row[1]; ?></td> 
         <td><? echo $row[2]; ?></td> 
         <td><? echo $row[3]; ?></td> 
         <td><? echo $row[4]; ?></td> 
         <td><input type="button" value="Delete" class="deleteBtn" /></td> 
        </tr> 
       <? } ?> 
      </table> 
     </fieldset> 
     <?php } ?> 

這是行不通的。想知道如何讓它工作。基本上我想把數組放入行中。

(我在這個問題的開始忘了迴音,我已經做了嘗試,我已經更新它是這樣,但仍然沒有工作)

的問題是什麼都沒有放出來,但這個數組包含可以肯定的數據,當我做了它的var_dump吐出:

array(10) { [0]=> string(4) "3344" ["purchaseNo"]=> string(4) "3344" [1]=> string(10) "2013-03-31" ["dateCreated"]=> string(10) "2013-03-31" [2]=> string(4) "John" ["Name"]=> string(4) "John" [3]=> string(5) "Mold1" ["mouldName"]=> string(5) "Mold1" [4]=> NULL ["courierName"]=> NULL } 
+0

嘗試回聲$行之前[1] –

+2

* 「這是行不通的。」 *這是無用作診斷信息。 *如何*不起作用? – cdhowie

+0

我加了回聲我忘了,我曾經這樣做過,但還在嘗試其他的東西,它仍然沒有迴應任何東西。 – Butterflycode

回答

2

前嘗試回聲$行[1] <?php echo $row[1]; ?>

所以你的答案是:

<? foreach ($searchresults as $row) { ?> 
         <tr class="tableRows"> 
          <td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td> 
          <td><a href="#"><?php echo $row[0]; ?></a></td> 
          <td><?php echo $row[1]; ?></td> 
          <td><?php echo $row[2]; ?></td> 
          <td><?php echo $row[3]; ?></td> 
          <td><?php echo $row[4]; ?></td> 
          <td><input type="button" value="Delete" class="deleteBtn" /></td> 
         </tr> 

    <? } ?> 
+0

謝謝:)這工作一些什麼,我需要修復自己,但這是完美的感謝你。 – Butterflycode

1

echo $row[i],而不是隻$row[i]

0

你不是做與變量什麼。您需要輸出:

<td><?= $row[1] ?></td> 

等等。

0

你需要echo的變量 像

<? foreach ($searchresults as $row) { ?> 
        <tr class="tableRows"> 
         <td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td> 
         <td><a href="#"><? echo $row[0]; ?></a></td> 
         <td><? echo $row[1]; ?></td> 
         <td><? echo $row[2]; ?></td> 
         <td><? echo $row[3]; ?></td> 
         <td><? echo $row[4]; ?></td> 
         <td><input type="button" value="Delete" class="deleteBtn" /></td> 
        </tr> 

    <? } ?> 

0

你必須使用echo用於顯示任何變量或文本。或使用

echo "<pre>"; print_r($row); echo "</pre>";顯示整個陣列

0

試試這個,希望能對大家的工作

<?php 
     foreach ($searchresults as $row) 
     { ?> 
     <tr class="tableRows"> 
      <td><img style="cursor: pointer;" src="img/expand.png" id="1" alt="hidden" onclick="changeSign()" /></td> 
      <td><a href="#"><?php echo $row[0]; ?></a></td> 
      <td><?php echo $row[1]; ?></td> 
      <td><?php echo $row[2]; ?></td> 
      <td><?php echo $row[3]; ?></td> 
      <td><?php echo $row[4]; ?></td> 
      <td><input type="button" value="Delete" class="deleteBtn" /></td> 
      </tr> 

<?php } ?>