Ho 2 tabelle: prodotto e del carrello, desidero combinare queste 2 tabelle e visualizzare i dati in array in base a una particolare condizione, come segue:combinare due tavoli e visualizzare i dati in un array
tutti i prodotti in una specifica categoria dovrebbero avere visualizzato e se un particolare utente hanno acquistato qualsiasi prodotto tra i prodotti indicati poi i suoi dettagli dovrebbero ottenere visualizzati anche di fronte a quel prodotto
Il codice che ho fatto fino ora è
$catid = $_REQUEST['catid'];
$userid = $_REQUEST['userid'];
$sql = "select * from productsize where catid = '".$catid."' GROUP BY productid";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$rows['catid'] = $row['catid'];
$rows['catname'] = $row['catname'];
$rows['productid'] = $row['productid'];
$rows['prodname'] = $row['prodname'];
$rows['prodimg'] = $row['prodimg'];
$row2[]=$rows;
}
}
echo "<pre>";
print_r($row2);
echo "</pre>";
Si dà una serie come questa
Array
(
[0] => Array
(
[catid] => 2
[catname] => C1
[productid] => 13
[prodname] => P1
[prodimg] =>
)
[1] => Array
(
[catid] => 2
[catname] => C1
[productid] => 14
[prodname] => P1
[prodimg] =>
)
[2] => Array
(
[catid] => 2
[catname] => C1
[productid] => 15
[prodname] => P3
[prodimg] =>
)
)
Ma la matrice finale che voglio al posto della matrice sopra è
Array
(
[0] => Array
(
[catid] => 2
[catname] => C1
[productid] => 13
[prodname] => P1
[prodimg] =>
[size] => Array
(
[0] => small
[1] => medium
[2] => large
[3] => perpiece
)
[cost] => Array
(
[0] => 10
[1] => 20
[2] => 30
[3] => 12
)
[purchasedsize] => Array
(
[0] => small
[1] => 0
[2] => large
[3] => 0
)
[purchasedquantity] => Array
(
[0] => 2
[1] => 0
[2] => 1
[3] => 0
)
[userid] => 1
)
[1] => Array
(
[catid] => 2
[catname] => C1
[productid] => 14
[prodname] => P1
[prodimg] =>
[size] => Array
(
[0] => small
[1] => medium
[2] => large
[3] => 0
)
[cost] => Array
(
[0] => 15
[1] => 20
[2] => 25
[3] => 0
)
[purchasedsize] => Array
(
[0] => 0
[1] => medium
[2] => 0
[3] => 0
)
[purchasedquantity] => Array
(
[0] => 0
[1] => 1
[2] => 0
[3] => 0
)
[userid] => 1
)
[2] => Array
(
[catid] => 2
[catname] => C1
[productid] => 15
[prodname] => P3
[prodimg] =>
[size] => Array
(
[0] => 0
[1] => medium
[2] => 0
[3] => perpiece
)
[cost] => Array
(
[0] => 0
[1] => 20
[2] => 0
[3] => 18
)
[purchasedsize] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
[purchasedquantity] => Array
(
[0] => 0
[1] => 0
[2] => 0
[3] => 0
)
[userid] => 0
)
)
Vista tabella dei prodotti (come si vedrà il tabella prodotto porta un productid e sotto ogni productid ci sono max 4 dimensioni (non ci saranno più di 4))
id catid catname productid prodsize cost prodname prodimg
1 2 C1 13 small 10 P1
2 2 C1 13 medium 20 P1
3 2 C1 13 large 30 P1
4 2 C1 13 perpiece 12 P1
5 2 C1 14 small 15 P2
6 2 C1 14 medium 20 P2
7 2 C1 14 large 25 P2
8 2 C1 15 perpiece 18 P3
9 2 C1 15 medium 20 P3
vista del carrello tavolo
id catid catname userid productid prodname prodsize quantity prodcost
1 2 C1 1 13 P1 large 1 30
2 2 C1 1 13 P1 small 2 10
3 2 C1 1 14 P2 medium 1 20
Qualcuno può aiutarmi a ottenere la matrice richiesto come il risultato?
anche se ottengo una matrice, ma i valori in esso non sono corretti – kavi
controllare il mio codice editied. Ho modificato la query –
@stile fornendo un array errato – kavi