I need to show specific products through a sql that I already have and that works well.
JQuery works perfectly for me, but with a button and PHP I do not really know how to do it.
The fact is that I have 2 combos on the home page and the user must select one and then another, to give the button to search and show these products depending on the chosen in those two combos.
I do not know how to put that form and where I should call that button to bring me those products.
I understand that I do it in the PHP and afterwards from the tpl I call that function, but I do not know where to start.
Does Alguin throw me a little light?
This is the jquery code that works for me:
function mostrarproductosporlocalidadyespecialidad(id_localid){
$("#productoselegidos").html("");
var especialidad = $("#sespecialidad").val();
var poblacion = id_localid;
$("#productoselegidos").append("Especialidad: " + especialidad + " Poblacion: " + poblacion);
var params = {
"especialidad" : especialidad,
"poblacion" : poblacion
};
$.ajax({
data: params,
url: 'adminasesmed/obtenerproductos.php',
type: 'post',
/*datatype: 'json',*/
success: function(response){
/*Ojo a ese $.parseJSON porque es un bug en jQuery*/
/*$.each($.parseJSON(response), function(index, data){
$("#productoselegidos").append("<br>Id de productos:" + data.id_product);
});*/
data = JSON.parse(response);
console.log(data);
for(i=0;i<data.length;i++){
/*console.log(data[i].id_product);*/
$("#productoselegidos").append("<div style='float:left'>" +
data[i].name +
"<br>" +
data[i].description_short +
"</div>");
}
}
})
}
Thanks