I am trying to open a new page that contains data from a database and I did this:
This is were I want to display my data
<table id="produse">
<thead>
<tr>
<th class="fluid">First Column</th>
<th class="fixed">Fixed Column</th>
<th class="fluid">Third Column</th>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
Entire JavaScript file to make an ideea of what I am trying to do:
$(function(){
//arata categoriile
$('.menu').on('click', function(){
$('#box').toggle('slide').show();
$.ajax({
url:'fetchsubmenu.php',
data : {nume : $(this).attr('data-value')},
dataType : 'json',
success:function(data){
console.log(data);// process your response
showObjects(data);
}
});
});
function showObjects(obiecte){
$('#box tbody').html('');
for(var i=0; i<obiecte.length; i++){ //Functia care arata obiectele
var aparat = obiecte[i];
$('#box tbody').append(getRow(aparat));
}
}
function getRow(aparat){
var row = '<tr>'+
'<td>' + '<a class="linkin" data-value='+aparat.id+' href="produs.html" >'+aparat.nume+'</a>' + '</td>'+
'</tr>';
return row;
}
// arata produsele dupa click pe linkul de categorie
$(document).on('click', '.linkin', function(){
$.ajax({
url:'foodstore.php',
dataType:'JSON',
data : {id : $(this).attr('data-value')},
success: function(data){
console.log(data);// process your response
var rows = '';
$.each(data,function(aparat){
rows+= '<td>'+'<div id="prod">'+
'<div>'+ '<img src='+aparat.imagine+' width="150" height="80" />' +'</div>'+
'<div>'+ aparat.nume + '</div>' + //functia care le aranjeaza
'<div>'+ aparat.pret +' lei' + '</div>'+
'<div>'+'<button type = "button" id = "comanda">'+'Comanda'+'</button>'+'</div>'
+ '</div>'+'</td>';
});
$('#produse').html(rows);
}
});
});
});
and the php File:
$conn=mysql_connect('localhost','root','');
mysql_select_db('alinDataBase');
$idcat = $_GET['id'];
$query = "SELECT * FROM electrocasnice WHERE subcat = '$idcat' ";
$result = mysql_query($query,$conn);
$output='';
while($row = mysql_fetch_array($result)){
$output=array(
"nume" => $row["nume"],
"pret" => $row["pret"],
"imagine" => $row["imaginepath"]
);
$records[] = $output;
}
echo json_encode($records);
mysql_close($conn);
So I what I want to do is once I click on the link, I want to open the page with the data from my DataBase , but the page is blank (excepting the table thead
).I know the code is a bit messy(I am a novice) thanks.