TheWebWeeb TheWebWeeb - 1 year ago 94
PHP Question

Need someone to correct my mysql querry for table creation

Hi i want to create a Table as that i can have in the one variable(gonna send it to js later on) and then display it. But result of my echo is only Table Head('Produkty','Ilość','Cena') Can you show me where i did mistakes or correct me?


header('Access-Control-Allow-Origin: *');
include "database.php";

$dane = array();
$tabela='<table class="table table-striped">

$sql_main="SELECT Products.`Name`,Orders_NEW.`Amount`,((Products.`Price`)*(Orders_NEW.`Amount`)) as 'PRICE' FROM `Orders_NEW` inner join `Products` on Orders_NEW.`Product`=Products.`ID` AND `Order_ID`=669";

$dane = $db->query($sql_main);

foreach($dane as $row)

$sql_second="SELECT SUM((Products.`Price`)*(Orders_NEW.`Amount`)) as 'SUMA' FROM `Orders_NEW` inner join `Products` on Orders_NEW.`Product`=Products.`ID` AND `Order_ID`=669";

$dane_second= array();

$dane_second= $db -> query($sql_second);

foreach($dane_second as $row)





Edited: Changed foreach into while($row = $dane->fetch_assoc())
Now my result is:

Produkt Ilość Cena


seems like variables like $row['Name'] etc is the problem here

Answer Source

I'm not sure if you have some sort of custom class with database.php, but if $db just contains mysqli object then you need to do the following:

$dane = $db->query($sql_main);

while($row = $dane->fetch_assoc()) {

Same goes for the second query (this assumes your SQL is correct and returning results by the way).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download