ajax - Get URL Parameter with PHP for Mysqli database search -


i'm trying work out how parameter url php. code starts bit of ajax firing php , alert response:

$.ajax({                                           url: 'blog/assets/php/load-blog.php',     datatype: 'json',         success: function(data){      alert(data);     }   }); 

then have php:

<?php   //==== connection variable   $con = new mysqli($host,$user,$pass,$database);     //==== url parameter   $urlparam =  $_get["date"];     //==== fetch data   $result = $con->query("select * $table date = '$urlparam'");     //==== create array   $blogarray = array();   while ($row = $result->fetch_row()) {     $blogarray[] = $row;   }     //==== echo json   echo json_encode($blogarray); ?> 

the url this:

http://www.mysite.com/blog/?date=2013-05-14 

the issue in of url parameter isn't being selected correctly don't know i've done wrong.

javascript

var date = '2013-05-14';  $.ajax({              type: "get",                                  url: 'blog/assets/php/load-blog.php',     datatype: 'json',     data: { date: date }     success: function(data){      alert(data);     } }); 

php

<?php //==== connection variable $con = new mysqli($host,$user,$pass,$database);   //==== url parameter $urlparam =  $_get["date"];  //==== prepared statement $stmt = $con->prepare("select id,name __table_name__ date = ?"); $stmt->bind_param("s", $urlparam ); $stmt->execute(); $stmt->bind_result($id, $name);  //==== create array $blogarray = array();  //==== fetch data    while ($stmt->fetch()) {     $blogarray[] = array(     'id' => $id,     'name' => $name     ); }  //==== close statement $stmt->close();  //==== echo json echo json_encode($blogarray); ?> 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -