Salutare, revin cu o problema, de data asta in Slim Framework.
Am 2 tabele.
Products:
ProductsMeta
El afiseaza asta momentan asa
As vrea sa afiseze ceva de genul ca sa pot folosi mai tarziu AJAX.
{
* productId: "1",
* productName: "PizzaElCozo"
* ingredients: "1";
* ingredients: "2";
* ingredients: "3";
},
Si sa adauge o linie pentru fiecare ingredient.
Acesta este codul:
<?php
header('Content-Type: application/json');
#Retrive pizzas list from db
$app->get('/api/pizzas', function(){
require_once('databaseconnect.php');
$queryPizzas = "select * from cms_products order by productName";
$result = $mysqli->query($queryPizzas);
#Tryout
$Ingredients = "
SELECT
*
FROM
cms_productsmeta as cpm, cms_products as cps
WHERE
cps.productId = cpm.productId
";
$resultIngredients = $mysqli->query($Ingredients);
while($row = $result->fetch_assoc()){
$data[] = $row;
}
if (!isset($data)){
echo "Nu exista nicio pizza in baza de date!";
} else {
echo json_encode($data);
}
});
Al 2-lea select, ar fi cum l-am gandit sa afiseze. Multumesc!