2015-08-18 59 views
0

我有一個手風琴菜單,包含數據庫帶來的數據。
菜單是一個列表或教授和他們的學科。
除了幻燈片的效果,當我點擊教授的名字時,我需要用數據庫中的數據填寫table
我可以得到該教授的id attribut,並獲得所需的數據(猜猜最好的選擇是ajax)。
但我不知道如何用數據填充表格。在點擊事件中填充表格

這裏是例子:http://codepen.io/Ghaleon/pen/zGQMpw

UPDATE:

我有一週的天表,也有紀律的時間列。我需要點擊教授,獲得他的ID,然後使用這個ID從該教授那裏檢索所有的學科(已經完成並創建一個子列表),但是我需要在正確的時間和星期幾插入正確的學科。

+0

在點擊事件$(「。prof-list h3」)中執行ajax-call。點擊(function()並用返回的數據填充某個元素? – bestprogrammerintheworld

+0

@bestprogrammerintheworld我會得到那個單擊的元素的屬性,這將是教授的ID。然後我想用這個ID從數據庫獲取數據並填寫表格......只需要一些指導就可以了。 – PlayHardGoPro

+1

無論誰給了downvote,至少評論這裏的原因......謝謝 – PlayHardGoPro

回答

0

如果我正確理解你的問題,我會做這樣的事情:

創建一個Ajax調用並在服務器端創建該表:

<?php 
function call_this_function_from_js_with_ajax() { 
    //Fetch data from database 
    $table_html ="<thead><th>{$title from db}</th></thead>'; 
    $table_html .= "<tbody>'; 
    $table_html .= "<tr><td>{$value1 from db}</td></tr>"; 
    $table_html .= "<tr><td>{$value2 from db}</td></tr>"; 
    $table_html .= "<tr><td>{$value3 from db}</td></tr>"; //etc etc 
    $table_html .= "</tbody>"; 
    return $table_html; 
} 
?> 

的jQuery:

$(".prof-list h3").click(function(){ 
    $(this).next().slideToggle(); 

    //Do ajax call and put the returned data into the the table 
    // 
    on success: 
    `$("table.col-md-6").html(data);` 

}) 

html

<table class="col-md-6"> 
{your returned data would be seen here} 
</table>