php - How to use a mySQL database to put HTML into a div -
currently, using jquery code put html file content div
$("#list li a").click(function(){ var id = this.id; $('#content').fadeout('fast', function(){ $.ajax({url:"./html/" + id + ".html",success:function(result){ $("#content").html(result); }}); }); $('#content').fadein('fast'); }); it pulling id anchor tags list
<ul id='list'> <li><a href="#" class="nav" id="home">home</a></li> <li><a href="#" class="nav" id="order">order form</a></li> </ul> the database have table named 'content' column named 'html' contains actual html code needs loaded div.
how use id in anchor tag corresponding row html code, , display in content div?
edit: so, figured out query:
$result = mysqli_query($con,"select content htmlcontent id='' "); my question is, how pass id ajax call in html page php function, , how return $result , display in #content div?
there multiple ways pass data server. namely, can use http method or http post method. right now, using jquery $.ajax method, which, default, uses get. in request, must pass data in url below format...
$.ajax({url:"./path/to/your/php/script?id=" + id ,success:function(result){ ... so rendered url end looking www.somesite.com/path/to/your/php/script?id=24
then on server, can grab id url php $_get method, so...
$id = $_get['id']; and can query database record id...
$result = mysqli_query($con,"select content htmlcontent id = " . $id); i recommend research basic http request types (get,post,put,delete) , implementations in php $_get , $_post methods.
Comments
Post a Comment