Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Calling the customers_id from mysql


DeltaWolf7

Recommended Posts

Hi,

 

I am a PHP newbie and i want to call the customers_id from the database.

How can I get the customers_id, related to the order (order_id?)

 

I tried writing the code using the examples I could find, but I could not get it to get the right value.

Link to comment
Share on other sites

This is the query:

SELECT customers_id FROM `orders` WHERE orders_id = 5123

with your order id instead. But that's just the sql query. If you want to make it work in your admin panel, that's more complex.

Link to comment
Share on other sites

This will likly give you more than 1 row returned though, as each order has more than 1 row entered into the orders table. You should probably use a distinct there...

 

SELECT DISTINCT customers_id FROM `orders` WHERE orders_id = 5123

-------------------------------------------------------------------------------------------------------------------------

NOTE: As of Oct 2006, I'm not as active in this forum as I used to be, but I still work with osC quite a bit.

If you have a question about any of my posts here, your best bet is to contact me though either Email or PM in my profile, and I'll be happy to help.

Link to comment
Share on other sites

Ok, so after what you said i cameup with this;

 

 

$query = tep_db_query("SELECT DISTINCT customers_id FROM `orders` WHERE orders_id = ". $oID);
     $result = $query;

	 

       echo "<br><font face=arial size=2><b>Your invoice number:</b> " . $oID . "</font>";
       echo "<br><font face=arial size=2><b>Your account number:</b> " . $result . "</font><br><br>";

 

The result was;

 

Your invoice number: 15
Your account number: Resource id #39

 

How do i get it to read that data and not display the pointer?

Link to comment
Share on other sites

So, are you looking for their name and the contents of the order?

Try showing an example of the result you're after.

Link to comment
Share on other sites

Ok, so after what you said i cameup with this;

$query = tep_db_query("SELECT DISTINCT customers_id FROM `orders` WHERE orders_id = ". $oID);
? ? ?$result = $query;

?	

? ? ? ?echo "<br><font face=arial size=2><b>Your invoice number:</b> " . $oID . "</font>";
? ? ? ?echo "<br><font face=arial size=2><b>Your account number:</b> " . $result . "</font><br><br>";

 

The result was;

 

Your invoice number: 15
Your account number: Resource id #39

 

How do i get it to read that data and not display the pointer?

 

if this is intended for a signed in user, then the customer_id is a registered variable which does not need to be retrieved.

 

simply use $customer_id

Treasurer MFC

Link to comment
Share on other sites

No this is not form the user. this is on the administrators invoice page.

I want to add this information to the bottom of the invoice so then I can find the cutomers account quicker.

 

Sorry to be a pain in the ass.

Link to comment
Share on other sites

 

Running a query like that just returns a resource identifier from MySQL you need to iterate through each record using fetch array functions, if you look at some of the osCommerce code you'll see lots of examples of this

 

$CustomersQuery = tep_db_query("SELECT DISTINCT customers_id FROM `orders` WHERE orders_id = ". $oID);

 while ($CustomerRecord = tep_db_fetch_array($CustomersQuery)) {
        //any fields in the query will be accessible through the array $CustomerRecord
        print "Your Customer Number is: {$CustomerRecord['customers_id']}";
        //on that line notice to print the value of an array variable within a string
       //enclose the array in {}, saves having to concatenate
       //If you dont like that method and want to concatenate
       print "Your Customer Number is: ".$CustomerRecord['customers_id'];
 }

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...