Jump to content
Sign in to follow this  
YePix

countries query

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);

 

Share this post


Link to post
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.

Share this post


Link to post
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);
?>

 


 

Share this post


Link to post
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);

 

Share this post


Link to post
Share on other sites

Always keep things as simple as you can;

tep_get_country_name($customer_country_id)

For a logged in customer.


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest Responsive osCommerce CE (community edition) here

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×