I have a question about jQuery UI Dialog box and showing dynamic content from a database. Here I have a table which is generating blog post using php and mysql and in that table, there is a column to view contents which are belong to each blog post.
That link is something like this -
$html .= " <td align='center'>\n";
$html .= " <a href='#' id='blog-$blog_id' class='view' >\n";
$html .= " <span class='icon-small ico-view-blog' title='View This Blog Post'></span>\n";
$html .= " </a>\n";
$html .= " </td>\n";
Clicking on above link I need to pop-up a jquery dialog to display all blog content. Eg: blog-title, author, image, blog etc.
I tried it with jqury and using separate php script to fetch blog contets like this. But it is not pop-up the dialog as I expect.
This is jquery I have used for the dialog -
$( "#dialog-view-blog" ).dialog({
autoOpen: false,
height: 450,
width: 650,
modal: true,
buttons: {
Cancel: function() {
$( this ).dialog( "close" );
}
},
position: {
my: "center top",
at: "center top",
of: "#content"
}
});
This is how I send a ajax request for the data from the php file to update the content in the dialog -
$( "a.view" ).click(function(e) {
e.preventDefault();
var clickblogID = this.id.split('-'); //Split string
var DbNumberID = clickedID[1]; //and get number from array
var blogId = 'blog_id='+ DbNumberID; //build a post data structure
$.ajax({
url: 'update_blog.php',
type: 'POST',
data: blogId,
success: function(data){
//alert(data);
//construct the data however, update the HTML of the popup div
//$('#dialog-view-blog').html(data);
$('#dialog-view-blog').dialog('open');
}
});
});
My code from update_blog.php page
if (isset($_POST['blog_id'])) {
//blog_id
$blogId = $_POST['blog_id'];
// If there is no any blog to this user display a string.
$q = "SELECT * FROM userblogs WHERE blog_id = ?";
// Prepare the statement:
$stmt = mysqli_prepare($dbc, $q);
// Bind the variables:
mysqli_stmt_bind_param($stmt, 'i', $blogId);
// Execute the query:
mysqli_stmt_execute($stmt);
//store result
mysqli_stmt_store_result($stmt);
// Get the number of rows returned:
$rows = mysqli_stmt_num_rows ($stmt);
if ( $rows == 1 ) {
$viewBlog = "<div id='dialog-view-blog' title='View Blogs'>\n";
$viewBlog .= " <h2>$blog_title</h2>\n";
$viewBlog .= " <p>$blog_author | $blog_added_date</p>\n";
$viewBlog .= " <p>";
$viewBlog .= " <img src='".UPLOAD_DIR.$userName."/".$blog_image."' alt='Image for Blog Title' />";
$viewBlog .= " $blog</p>";
$viewBlog .= "</div>\n";
echo $viewBlog;
}
Can anybody pointed me where I have gone wrong? Any comments are greatly appreciated.
Thank you.
open
method for the dialog when clicking the link, again. – EmCo Aug 26 at 16:53var DbNumberID = clickblogID [1];
instead ofvar DbNumberID = clickedID[1];
? – EmCo Aug 26 at 17:16