2013-03-11 46 views
-7

如何DIV值傳遞給數據庫在PHP MySQL的如何DIV值傳遞給MySQL查詢在PHP

比方說

<div id='item'>50</div> 

IM是否有可能傳遞div值50到選擇查詢條件

說例如

<php 
    $sql = "SELECT * FROM TABLE_NAME WHERE id = 50" 
?> 
+1

http://en.wikipedia.org/wiki/AJAX – 2013-03-11 16:54:31

+1

閱讀有關[AJAX](HTTP:/ /api.jquery.com/jQuery.ajax/)! – 2013-03-11 16:54:36

+0

'$('#item').text()' – Andy 2013-03-11 16:55:13

回答

2

[笑話]只是用戶名前加A和tada!你得到答案! [/笑話]

使用Javascript -

var reqText = document.getElementById('source_div').innerHTML; 
var xhr = new XMLHttpRequest(); 
xhr.open('GET', 'test.php?req='+reqText, true); 
xhr.onload = function() { 
    //do stuff 
}; 
xhr.send(null); 

test.php的 -

<?php 
    $req = $_GET['req']; 
    //use $req in your sql query. 
?>