Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

countries query


YePix

Recommended Posts

 

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

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

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

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

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...