2014-01-17 73 views
3

我使用的是jtable.org的jtable。問題是,我有一個圖像存儲在我的數據庫(MySQL),我想要顯示在網頁上使用jtable與其他列的圖像。所有其他列正在正確顯示,但圖像不顯示。這是我的HTML代碼:圖像無法在jtable中顯示?

<html> 
    <head> 

    <link href="themes/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" type="text/css" /> 
    <link href="Scripts/jtable/themes/lightcolor/blue/jtable.css" rel="stylesheet" type="text/css" /> 

    <script src="scripts/jquery-1.6.4.min.js" type="text/javascript"></script> 
    <script src="scripts/jquery-ui-1.8.16.custom.min.js" type="text/javascript"></script> 
    <script src="Scripts/jtable/jquery.jtable.js" type="text/javascript"></script> 

    </head> 
    <body> 
    <div id="PeopleTableContainer" style="width: 960px;"></div> 
    <script type="text/javascript"> 

     $(document).ready(function() { 

      //Prepare jTable 
      $('#PeopleTableContainer').jtable({ 
       title: 'Table of people', 
       actions: { 
        listAction: 'PersonActions.php?action=list', 
        updateAction: 'PersonActions.php?action=update' 

       }, 
       fields: { 
        PersonId: { 
         key: true, 
         create: false, 
         edit: false, 
         list: false 
        }, 
        Name: { 
         title: 'Product', 
         width: '20%' 
        }, 
        SellingPrice: { 
         title: 'Selling Price', 
         width: '15%', 
        }, 
        CostPrice: { 
         title: 'Cost Price', 
         width: '15%', 
        }, 
        Remarks: { 
         title: 'Remarks', 
         width: '15%', 
        }, 
        Stock: { 
         title: 'Stock', 
         width: '15%', 
        }, 
        Pic: { 
         title: 'Image', 
         width: '50%', 
         edit: false 
        } 
       } 
      }); 

      //Load person list from server 
      $('#PeopleTableContainer').jtable('load'); 

     }); 

    </script> 

    </body> 
</html> 

,這是我與其他功能的SELECT查詢:

//從數據庫

$result = mysql_query("SELECT * FROM people;"); 

    //Add all records to an array 
    $rows = array(); 
    while($row = mysql_fetch_array($result)) 
    { 
     $rows[] = $row; 
    } 

    //Return result to jTable 
    $jTableResult = array(); 
    $jTableResult['Result'] = "OK"; 
    $jTableResult['Records'] = $rows; 
    print json_encode($jTableResult); 

回答

0

我想出了另一種方式,如果我們將圖像的地址存儲在數據庫中,而不是簡單地使用圖像的地址(鏈接)填充我們的列。

0

記錄當我面臨同樣的問題,下面的鏈接幫助: Dynamically add images to JTable cells

對不起,我希望我仍然有我的舊代碼,我知道給鏈接是皺眉。也許其他人絆倒在這個頁面上可能會發現它有用。

圖像來自您的數據庫的事實不應該有所作爲,除非您沒有正確檢索它。嘗試使用本地圖像,如果可以讓它起作用,那麼您將問題隔離到不正確地從數據庫獲取圖像。在過去,我只嘗試過鏈接到數據庫上的圖像,該圖像指向我的ftp服務器。這意味着我不必在resultSet中傳輸圖像,只需通過FTP獲取。