YePix Posted December 27, 2018 Share Posted December 27, 2018 Hi guys, I really need to read the country from the database. Can someone help me with the query? $countries_query = tep_db_query("select ab.address_book_id as address_book_id, ab.customers_id as customers_id, ab.entry_country_id as entry_country_id, c.countries_id as countries_id, c.countries_name as countries_name from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_COUNTRIES . " c where countries_id and customers_id = '" . (int)$customer_id . "'"); $countries = tep_db_fetch_array($countries_query); Link to comment Share on other sites More sharing options...
MrPhil Posted December 27, 2018 Share Posted December 27, 2018 Maybe if you told us your starting point (what information you have), and what information you're trying to get, we could be of help. As it is, I can't tell what you're trying to do. Also, the phrase where countries_id and customers_id = is certainly incorrect SQL. Link to comment Share on other sites More sharing options...
♥JcMagpie Posted December 27, 2018 Share Posted December 27, 2018 7 hours ago, YePix said: Can someone help me with the query? I use this little script to pull customer data when needed it contains the address details it may be of help. <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "username", "password", "databasename"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Attempt select query execution $sql = "SELECT * FROM orders,orders_products where orders.orders_id = orders_products.orders_products_id";// GROUP BY orders_products.orders_id"; if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ echo "<table>"; echo "<tr>"; echo "<th>id</th>"; echo "<th>name</th>"; echo "<th>email</th>"; echo "<th>telephone</th>"; echo "<th>orders-ID</th>"; echo "<th>company name</th>"; echo "<th>country</th>"; echo "<th>product ID</th>"; echo "<th>Model</th>"; echo "<th>Name</th>"; echo "<th>quantity</th>"; echo "<th>Price</th>"; echo "</tr>"; while($row = mysqli_fetch_array($result)){ echo "<tr>"; echo "<td>" . $row['customers_id'] . "</td>"; echo "<td>" . $row['customers_name'] . "</td>"; echo "<td>" . $row['customers_email_address'] . "</td>"; echo "<td>" . $row['customers_telephone'] . "</td>"; echo "<td>" . $row['orders_id'] . "</td>"; echo "<td>" . $row['customers_company'] . "</td>"; echo "<td>" . $row['customers_country'] . "</td>"; echo "<td>" . $row['products_id'] . "</td>"; echo "<td>" . $row['products_model'] . "</td>"; echo "<td>" . $row['products_name'] . "</td>"; echo "<td>" . $row['products_quantity'] . "</td>"; echo "<td>" . $row['products_price'] . "</td>"; echo "</tr>"; } echo "</table>"; // Free result set mysqli_free_result($result); } else{ echo "No records matching your query were found."; } } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); ?> Link to comment Share on other sites More sharing options...
YePix Posted December 27, 2018 Author Share Posted December 27, 2018 Thanks guys, I solved it. $countries_query = tep_db_query("select ab.customers_id as customers_id, ab.entry_country_id as entry_country_id, c.countries_id as countries_id, c.countries_name as countries_name from " . TABLE_ADDRESS_BOOK . " ab, " . TABLE_COUNTRIES . " c where customers_id = '" . (int)$customer_id . "' and entry_country_id = countries_id"); $countries = tep_db_fetch_array($countries_query); Link to comment Share on other sites More sharing options...
burt Posted January 6, 2019 Share Posted January 6, 2019 Always keep things as simple as you can; tep_get_country_name($customer_country_id) For a logged in customer. Link to comment Share on other sites More sharing options...
YePix Posted January 10, 2019 Author Share Posted January 10, 2019 why complicated when it just works. Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.