2013-02-15 303 views
0

我有什麼:在php mysql表提交按鈕

<table class="sortable table table-hover table-bordered"> 
    <thead> 
    <tr> 
    <th>CPU</th> 
    <th>Speed</th> 
    <th>Cores</th> 
    <th>TDP</th> 
    <th>Preformace</th> 
    <th>Overclocing</th> 
    <th>Price</th> 
    <th>Buy</th> 
    </tr> 
    </thead> 
    <tbody> 
    <?php $i=0 ; 
    do { 
    $preformace = $row_Procesory['Preformace']; 
    $over = $row_Procesory['Overclocing']; 
    $i++; ?> 
    <tr> 
    <td><?php echo $row_Procesory['CPU']; ?></td> 
    <td><?php echo $row_Procesory['Speed']; ?></td> 
    <td><?php echo $row_Procesory['Cores']; ?></td> 
    <td><?php echo $row_Procesory['TDP']; ?></td> 
    <td><?php echo " 
    <script type='text/javascript'> 
    $(document).ready(function() { 
    $('#progressbarP$i').height(10).progressbar({ 
            value : 1 
            }); 
    $('#progressbarP$i .ui-progressbar-value').animate(
    {width: '$preformace%'},{queue: false}); 
    }); 
    </script> 
    <div id='progressbarP$i' title='$preformace'></div> 
    ";?></td> 

    <td><?php echo " 
    <script type='text/javascript'> 
    $(document).ready(function() { 
    $('#progressbarO$i').height(10).progressbar({ 
            value : 1 
            });    
    $('#progressbarO$i .ui-progressbar-value').animate({ 
     width: '$over%' 
     }, 1000); 
    }); 
    </script> 
    <div id='progressbarO$i' title='$over'></div> 
    ";?></td> 

    <td><?php echo $row_Procesory['Price']; ?></td> 
    <!-- BUTTON SECTION --> 
    <td><?php echo "<button class='btn btn-success' type='button' align='CENTER'>Add</button>";?></td> 
    </tr> 
    <?php } while ($row_Procesory = mysql_fetch_assoc($Procesory)); ?> 
</tbody> 
</table> 

基本上即時通過MySQL的循環和顯示行。在preformace和超頻列即時通訊顯示動畫jquery progresbar值從MySQL。我也使用bootstrap和sortable.js來進行表格排序。

How it looks like:

我想要什麼: 當我點擊添加按鈕處理器的名稱將sended到test.php的作爲變量。 我甚至不知道如何定位name元素使用jQuery:d

+0

請進行的jsfiddle所以我們可以幫助更多的 – Sedz 2013-02-15 21:13:59

+0

它從我的MySQL服務器動態這將是簡單的表中的jsfiddle – 2013-02-15 21:27:20

+0

是的,我知道,但它會更容易測試它作爲HTML和JS反正看看在我的回答 – Sedz 2013-02-15 21:28:40

回答

0

如果我明白你的問題就在這裏的東西可以幫助

<table class="sortable table table-hover table-bordered"> 
    <thead> 
    <tr> 
    <th>CPU</th> 
    <th>Speed</th> 
    <th>Cores</th> 
    <th>TDP</th> 
    <th>Preformace</th> 
    <th>Overclocing</th> 
    <th>Price</th> 
    <th>Buy</th> 
    </tr> 
    </thead> 
    <tbody> 
    <?php $i=0 ; 
    do { 
    $preformace = $row_Procesory['Preformace']; 
    $over = $row_Procesory['Overclocing']; 
    $i++; ?> 
    <tr> 
    <td><?php echo $row_Procesory['CPU']; ?></td> 
    <td><?php echo $row_Procesory['Speed']; ?></td> 
    <td><?php echo $row_Procesory['Cores']; ?></td> 
    <td><?php echo $row_Procesory['TDP']; ?></td> 
    <td><?php echo " 
    <script type='text/javascript'> 
    $(document).ready(function() { 
    $('#progressbarP$i').height(10).progressbar({ 
            value : 1 
            }); 
    $('#progressbarP$i .ui-progressbar-value').animate(
    {width: '$preformace%'},{queue: false}); 
    }); 
    </script> 
    <div id='progressbarP$i' title='$preformace'></div> 
    ";?></td> 

    <td><?php echo " 
    <script type='text/javascript'> 
    $(document).ready(function() { 
    $('#progressbarO$i').height(10).progressbar({ 
            value : 1 
            });    
    $('#progressbarO$i .ui-progressbar-value').animate({ 
     width: '$over%' 
     }, 1000); 
    }); 
    </script> 
    <div id='progressbarO$i' title='$over'></div> 
    ";?></td> 

    <td><?php echo $row_Procesory['Price']; ?></td> 
    <!-- BUTTON SECTION --> 
    <td><?php echo "<button class='btn btn-success pro_btn' processor = '".$row_Procesory['CPU']."' type='button' align='CENTER'>Add</button>";?></td> 
    </tr> 
    <?php } while ($row_Procesory = mysql_fetch_assoc($Procesory)); ?> 
</tbody> 
</table> 

該溶液(處理器屬性)是避免選擇它可以是其他的東西,我們可以提供,如果你想它

$('.pro_btn').die('click').live('click',function(e){ 
    var name = $(this).attr('processor'); 
    $.post('test.php',{'processor_name':name}, function(response) { 
    // log the response to the console 
     console.log("Response: "+response); 
    }); 

}); 

如果你不想使用屬性,你可以做這樣的事情

var name = $(this).closest('tr').find('td:first').text(); 

我希望這能幫助:)

+0

謝謝你,明天我會試試看。我不知道我能做出自己的屬性。 – 2013-02-15 21:32:20

+0

不,你可以,明天告訴我結果 – Sedz 2013-02-15 21:32:58

+2

雖然你可以做出自己的屬性,但不推薦。 HTML5爲用戶定義的屬性保留了'data-XXX',你應該使用這個。 jQuery支持使用'.data()'方法:'$(this).data('processor')'相當於$(this).attr('data-processor')'。 – Barmar 2013-02-15 21:35:57

0

捕獲點擊事件,並找到最接近的「TR」,然後是「TR」的第一個「TD」。這將是這樣的:

$(this).closest('tr').find('td:first').text(); 

或者得到您的按鈕,這將是td,他們td的父母paren。這將是tr。最後得到第一個td。

$(this).parent().parent().find('td:first').text(); 

或者只是添加一個額外的屬性到您的按鈕,然後得到的價值。

$(this).attr('processor'); 
+0

和Sedz的答案一樣嗎? – Barmar 2013-02-15 21:41:24

+0

也許同時 – yngrdyn 2013-02-18 16:11:09

+0

不,他在你的前幾分鐘。你現在不能告訴它,因爲這樣會縮短時間。但如果你的答案在兩分鐘之內,我絕不會發表這樣的評論。 – Barmar 2013-02-18 16:26:47