par
fliewight » 15 oct. 2021, 16:39
Oui, la requête n'était pas bonne.
J'ai d'ailleurs revu mon code à l'aide de requêtes préparées qui m'ont permises de supprimer le 2ème while :
Code : Tout sélectionner
<table id="commandes">
<tr>
<td id="id">ID</td>
<td id="nom">Nom de l'article</td>
<td id="stock">Stock</td>
</tr>
<?php
$stmt1 = $conn->prepare("SELECT product_id FROM fyz7g_wc_product_meta_lookup");
$stmt2 = $conn->prepare("SELECT post_title, stock_status, stock_quantity FROM fyz7g_posts INNER JOIN fyz7g_wc_product_meta_lookup ON fyz7g_posts.ID = fyz7g_wc_product_meta_lookup.product_id WHERE ID = ?");
$stmt1->execute();
foreach ($stmt1 as $row) {
$nb = $row[0];
echo $nb."<br>";
}
while ($row = $req->fetch())
{
if ($row['order_id']) {
$order_id = $row['order_id'];
echo "<tr><td>".$row['order_id']."</td>";
}
if ($row['order_item_name'])
{
if ($row['order_item_name'] != "Retrait en boutique" && $row['order_item_name'] != "Panier de légumes" && $row['order_item_name'] != "Retrait à la Ferme")
{
echo "<td>".$row['order_item_name']."</td>";
}
}
if ($row['stock_status']) {
$statut = '';
switch ($row['stock_status']) {
case 'outofstock' : $statut = 'Rupture de stock'; break;
case 'onbackorder' : $statut = 'En réapprovisionnement'; break;
case 'instock' : $statut = 'En stock'; break;
}
}
if ($row['stock_quantity']) {
if ($statut == 'En stock') echo "<td>".$statut += $row['stock_quantity']."</td>";
}
}
?>
</table>
Désormais, je peux récupérer tous mes ID, et je souhaiterais récupérer ma liste d'ID dans un tableau en dehors de la boucle foreach, mais je peine à y arriver à cet endroit là :
Quelqu'un sait-il comment je puisse y arriver ?
Merci d'avance.
P.S. : les tabulations ne fonctionnent plus ?!
Oui, la requête n'était pas bonne.
J'ai d'ailleurs revu mon code à l'aide de requêtes préparées qui m'ont permises de supprimer le 2ème while :
[code]<table id="commandes">
<tr>
<td id="id">ID</td>
<td id="nom">Nom de l'article</td>
<td id="stock">Stock</td>
</tr>
<?php
$stmt1 = $conn->prepare("SELECT product_id FROM fyz7g_wc_product_meta_lookup");
$stmt2 = $conn->prepare("SELECT post_title, stock_status, stock_quantity FROM fyz7g_posts INNER JOIN fyz7g_wc_product_meta_lookup ON fyz7g_posts.ID = fyz7g_wc_product_meta_lookup.product_id WHERE ID = ?");
$stmt1->execute();
foreach ($stmt1 as $row) {
$nb = $row[0];
echo $nb."<br>";
}
while ($row = $req->fetch())
{
if ($row['order_id']) {
$order_id = $row['order_id'];
echo "<tr><td>".$row['order_id']."</td>";
}
if ($row['order_item_name'])
{
if ($row['order_item_name'] != "Retrait en boutique" && $row['order_item_name'] != "Panier de légumes" && $row['order_item_name'] != "Retrait à la Ferme")
{
echo "<td>".$row['order_item_name']."</td>";
}
}
if ($row['stock_status']) {
$statut = '';
switch ($row['stock_status']) {
case 'outofstock' : $statut = 'Rupture de stock'; break;
case 'onbackorder' : $statut = 'En réapprovisionnement'; break;
case 'instock' : $statut = 'En stock'; break;
}
}
if ($row['stock_quantity']) {
if ($statut == 'En stock') echo "<td>".$statut += $row['stock_quantity']."</td>";
}
}
?>
</table>[/code]
Désormais, je peux récupérer tous mes ID, et je souhaiterais récupérer ma liste d'ID dans un tableau en dehors de la boucle foreach, mais je peine à y arriver à cet endroit là :
[code]foreach ($stmt1 as $row) {
$nb = $row[0];
echo $nb."<br>";
}[/code]
Quelqu'un sait-il comment je puisse y arriver ?
Merci d'avance.
P.S. : les tabulations ne fonctionnent plus ?!