bambinou1980 Posted January 4, 2016 Share Posted January 4, 2016 Hello, I am not understanding why, I do not get an array output there, is there a problem with my php code? <?php $query = "SELECT o.orders_id, date_format(o.due_date, '%d/%m/%Y') as day, o.customer_paid, p.product_price, p.product_quantity, p.product_price * p.product_quantity AS totals, p.orders_orders_id FROM orders AS o LEFT JOIN products_ordered AS p ON o.orders_id = p.orders_orders_id WHERE YEAR(o.due_date) = YEAR(CURDATE()) AND MONTH(o.due_date) = MONTH(CURDATE()) WHERE o.customer_paid = 'PAID' GROUP BY o.orders_id"; if (mysqli_connect_errno()) die('Could not connect: ' . mysql_error()); $return_arr = array(); if ($result = mysqli_query($connection, $query)) { while ($row = mysqli_fetch_assoc($result)) { $row_array['orders_id'] = $row['orders_id']; $row_array['product_price'] = $row['product_price']; array_push($return_arr, $row_array); } } mysqli_close($connection); echo json_encode($return_arr); ?> Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted January 4, 2016 Share Posted January 4, 2016 The second "WHERE" in the query needs to be "AND" Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted January 4, 2016 Share Posted January 4, 2016 is there a problem with my php code? rather than just asking someone else which keys to push to fix a problem, how about debugging the problem yourself? between the forums that i know you post on, you have several hundred posts. at this point, you should be able to isolate a problem with your code and queries to at least the pin down where the problem is at and by looking at where the problem is at, you may be able to solve it yourself. is your query running or is it producing an error? do you have error checking and error handling logic in your code for the query? is your query running, but not matching any rows? do you have any logic in your code to test for this condition and output an appropriate result for the case of no matching rows? Quote Link to comment Share on other sites More sharing options...
bambinou1980 Posted January 4, 2016 Author Share Posted January 4, 2016 Mac Gyver, I have no words for your comments and will have to change my username as I don't like when someone is following me on the internet. "between the forums that i know you post on, you have several hundred posts"<---- NSA? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 5, 2016 Share Posted January 5, 2016 I see a mysqli query call, a mysqli connect error check and a MySQL (no I) error code display. But I don't see how you made your db connection. Dare I ask if it was MySQL (no I)? Are you doing error checking during your development as a good programmer usually (always?) does? And of course the faulty query statement that Barand previously pointed out. PS - you don't think that people who post across multiple forums aren't noticed by those who visit the boards regularly? On what planet do you live? If I were you I would be more concerned about the weakness in your debugging ability that was pointed out to you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.