php
  • arrays
  • forms
  • xhtml
  • psql
  • 2014-11-21 37 views 0 likes 
    0

    好吧我調整以獲取複選框POST數據並顯示在結帳頁面上的每一個,但我有的問題是當它到達第四cololumn它停止它時,它擊中某個字符限制也如何將它變成結賬頁上的表。PHP數組顯示不顯示所有列

    數據庫代碼片段:

    print '<td><input type="checkbox" name="check_list[]"value='. $getColumn[0]. $getColumn[1].  $getColumn[2]. $getColumn[3]. $getColumn[4]. $getColumn[5].$getColumn[6].$getColumn[7].$getColumn[8].$getColumn[9].'</td>'; 
    for ($column = 1; $column < pg_num_fields($res); $column++) 
    { 
    print "<td>" . $getColumn[$column] . "</td>"; 
    } 
    } 
    print '</table>' 
    

    結帳頁面

    <?php 
    
    echo "<hr />\n"; 
    $res = pg_query ($con, "select count(ref) from music"); 
    $a = pg_fetch_row($res); 
    echo "<p>Total " . $a[0] . " music in database.</p>"; 
    
    echo "<table border='1'>\n<thead>\n<tr>\n"; 
    echo "<th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th>  <th>Price</th><th>Description</th>\n"; 
    echo "</tr>\n</thead>\n<tbody>\n"; 
    $res=pg_query($con, "SELECT * from music ORDER BY ref"); 
    while ($a = pg_fetch_array ($res)) 
    { 
    echo "<tr>"; 
    for ($j = 0; $j < pg_num_fields($res); $j++) { 
        // htmlspecialchars converts things like & to HTML entity codes 
         echo "<td>" . htmlspecialchars($a[$j], ENT_QUOTES) . "</td>"; 
        } 
    echo "</tr>\n"; 
    } 
    echo "</tbody>\n</table>"; 
    
    
    
    ?> 
    
    +0

    我敢打賭它沒有擊中任何「字符限制」,而是輸出包括一個破壞你的HTML的值。查看頁面源代碼並查看它是否全部存在。您需要將其轉義爲HTML輸出,例如'htmlspecialchars($ getColumn [$ column'])'或'echo「

    」。 htmlspecialchars($ selected)。「

    」;'http://php.net/manual/en/function.htmlspecialchars.php – 2014-11-21 15:06:02

    +0

    我也注意到'value ='屬性沒有被引用。如果有任何空格,它將不會被HTML正確解析。你需要確保它的結果是'value =「abcdefg 1234567」'用引號括起來。在'name =「check_list []之後的'value ='之前缺少一個空格''並且''標籤缺少其''' – 2014-11-21 15:07:31

    +0

    謝謝你修正了輸出,但現在我需要把它放到一個表中,我不太清楚該怎麼做。 – harris 2014-11-21 18:09:34

    回答

    1

    我肯定,你想做到以下幾點:

    print '<table>'; 
    for ($column = 1; $column < pg_num_fields($res); $column++) { 
        echo '<tr>'; 
        print '<td><input type="checkbox" name="check_list[]" value="'.$getColumn[$column] .'" /></td>'; 
        print "<td>" . $getColumn[$column] . "</td>"; 
        echo '</tr>'; 
    } 
    print '</table>'; 
    
    +0

    是啊沒有工作給出了錯誤 – harris 2014-11-21 17:58:45

    +0

    我不能幫你,如果你不告訴我,你會得到什麼錯誤。 – vaso123 2014-11-27 12:04:12

    相關問題