I received 10 name strings from mysqldb to $.Ajax (function(data) now how to split that (data) as it is echoing all the 10 names in one div i want to echo it in 10 different divs
$(document).ready(function() {
$('ul.sub_menu a').click(function() {
var txt = $(this).text();
//console.log("you clicked"+txt);
$.ajax({
type: 'POST',
url: 'thegamer.php',
data: {send_txt: txt},
success: function( data ){
//now echo the data where you want
// for example
$('#sliderid').html( data );
// or you can see in on firebug
console.log( 'Return:' + data );
}
});
});
});
my php code
$family = mysql_real_escape_string($_REQUEST['send_txt'], $link);
$query = "SELECT imgurl FROM images WHERE family='$family'";
//Query database
$result = mysql_query($query, $link);
//Output result, send back to ajax as var 'response'
$i=0;
echo "<table>";
if(mysql_num_rows($result) > 0){
//Fetch rows
while($row = mysql_fetch_array($result)){
echo "<tr><td>".$row['imgurl']."</td></tr>";
$i+=1;
}
}else{
echo "<tr><td>No results matching family \"$family\"</td></tr>";
}
echo "</table>";
There are many ways to do this:
1) you can do it in the php side: e.g. :
2) you can return the data as JSON (using json_encode() in php) and then loop through it in js