This is a bit complex for me, im still a newbie lol. Consider the the following blocks of code. Jquery's Ajax which loops a php block and appends new feed to some div. PHP returns more than one result in this case as an example it returns "Name" and "Slogan". After ajax recieved results, i want to appended the following as a template, but where there's php to be a variable since this will change every time this template is appended. Here's the html template.
<div id="BuzFeedResult1">
<?php
require_once 'php/db_conx.php';
$Result = mysql_query("SELECT * FROM profiles ORDER BY lastupdated DESC LIMIT 1") or die (mysql_error());
while($row = mysql_fetch_array($Result))
{ ?>
<div id="ProfileDiv">
<div>
<span class="flat-menu-button"><?php echo $row['name'];?></span>
<span class="flat-menu-button"><?php echo $row['slogan'];?>
</span>
<?php
}?>
</span>
</div>
</div>
</div>
Question. How do i go about getting the above template into ajax inside this div.
var $buzfeedresults = $("<div id='BuzFeedResult" + counter + "'></div>");
and then append it accordingly like the following does append "div".
var get_fb = (function() {
var counter = 0;
var $buzfeed = $('#BuzFeed');
return function(){
$.ajax({
type: "POST",
url: "../php/TopBusinesses_Algorythm.php"
}).done(function(feedback) {
counter += 1;
//Divs being appended.
var $buzfeedresults = $("<div id='BuzFeedResult" + counter + "'></div>");
$buzfeedresults.text(feedback);
$buzfeed.append($buzfeedresults);
var $buzfeedDivs = $buzfeed.children('div');
if ($buzfeedDivs.length > 10) { $buzfeedDivs.last().remove(); }
setTimeout(get_fb, 4000);
}).fail(function(jqXhr, textStatus, errorThrown) {
var $buzfeedresults = $("<div id='BuzFeedError'></div>");
$buzfeedresults.text('Error: ' + textStatus);
if (typeof console !== 'undefined') {
console.error(jqXhr, textStatus, errorThrown);
}
});
};
})();
get_fb()
This question may sound unclear please ask for clarity where needed. If Json can be more neater and short please suggest a structure i can use.