Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Database Query Question


Guest

Recommended Posts

Hi?

I am trying to query the database to return the products_id using the model number.

Here is my code:

 

// Query Product_ID

if (isset($model) && isset($description)){

 

//Query Database for products_id

 

$products_id_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_model = '" . $model . '" and pd.products_name ="' . $description . "' and pd.language_id = '" . (int)$languages_id . '");

 

$products_ID = tep_db_fetch_array($products_ID_query);

 

}

 

Ok the problem is that the query seems to execute ok.... I am guessing but, I end up with the following error:

 

Parse error: parse error, unexpected T_STRING in /home/sites/shop/web/catalog/product_info.php on line 43

 

 

NB: I am getting the model and description from cookies that I set in a different script.

 

I checked line 43 and it was ok. And when I commented out the query it worked fine. Is there a problem with the way I am doing the query? Is there a simpler way I can get the products_id ?

 

I just need a short query that returns the products_id. I have the products_model and products_description

 

Any help would be appreciated

Link to comment
Share on other sites

After a quick look try:

 

$products_id_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_model = '" . $model . "' and pd.products_name ='" . $description . "' and pd.language_id = '" . (int)$languages_id . "'");

Your online success is Paramount.

Link to comment
Share on other sites

Thank you. That works ok, but how do I get the products_id?

Is the value contained in $products_id_query ? I tried to print out the value of products_id_query and got

 

code:

echo "Products_id_query =" . $product_id_query ;

 

ouput:

products_id_query =Resource id #36

 

 

I also tried to use this but the value was null.

 

$products_id = tep_db_fetch_array($products_id_query);

echo "<br> products_id =" . $products_id;

 

OUTPUT:

-----------

products_id =

 

 

Any ideas why that would happen?

 

Thanks

 

After a quick look try:

 

$products_id_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_model = '" . $model . "' and pd.products_name ='" . $description . "' and pd.language_id = '" . (int)$languages_id . "'");

Link to comment
Share on other sites

$products_id_query = tep_db_query("select products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_model = '" . $model . '" and pd.products_name ="' . $description . "' and pd.language_id = '" . (int)$languages_id . '");

$products_ID = tep_db_fetch_array($products_ID_query);

echo $products_ID['products_id'];

Link to comment
Share on other sites

Sorry I had the variables mixed up before but now they are all lowercase. as in

 

$products_id_query and $products_id

 

And still Nothing. here is what I have now:

 

 

if (isset($model) && isset($description)){

print "Cookies Model Value: " . $model . " Description Value: " . $description ." <br><br>";

 

//Query Database for products_id

$products_id_query = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_model = '" . $model . "' and pd.products_name ='" . $description . "' and pd.language_id = '" . (int)$languages_id . "'");

 

echo "products_id = " . $products_id_query['products_id'];

 

}

else

echo "Cookies not set";

Link to comment
Share on other sites

That Give me this:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sites/shop/web/catalog/includes/functions/database.php on line 99

Link to comment
Share on other sites

All this is on product_info.php

 

The echoing is just to make sure I have the right data (product_id) which I need for another fucntion that requires me to pass the products_id

 

By the way I am echoing it before any HTML tags.

 

What page are you trying to echo the product id out on?

Link to comment
Share on other sites

I got it to echo out "A" product ID. I don't know if its the right one. For me it just displays theh first one. But its how the tables are linked up.

 

$products_id_query = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_DESCRIPTION . " pd on p.products_model = '" . $model . "' and pd.products_name ='" . $description . "' and pd.language_id = '" . (int)$languages_id . "'");
$product_id = tep_db_fetch_array($products_id_query);

echo $product_id['products_id'];

Link to comment
Share on other sites

If I use $products_id = tep_db_fetch_array($products_id_query); the out put is

products_id Array

 

That Means its an array I hope. But it only has one item. I tried to to print it with

 

echo $products_id[0]; and echo $products_id[1]; but nada. Nuthing am, it is just empty.

 

I also checked my cookies and they have the info.

 

echo "Cookies Model Value: " . $model . " Description Value: " . $description ." <br><br>";

 

So I really dunno whats up. Any luck Dennis?

Link to comment
Share on other sites

I just realized I dont even need to use the description. Can we just use the model number to and products_table to get the Id coz men I have over 80 thousand items it will have to query and do the join before it finds it. I just tried and it took quite a few seconds to load

Link to comment
Share on other sites

LOL am kinda confused today. All I need is the products_id and I have the model number and each model number is unique in the database and so is the product_id.

 

Would the simplest and fastest way to do it be; using the products_model and querying the product table?

 

Coz I think the description is messed up. I might have some redundant descriptions in the databse.

 

 

I am trying to understand why you have all this extra information...

Link to comment
Share on other sites

Finally, Ok, I got it. It works faster too. All I had to do is this:

 

 

$products_id_query = tep_db_query("select p.products_id from " . TABLE_PRODUCTS . " p where p.products_model = '" . $model . "'");

$product_id = tep_db_fetch_array($products_id_query);

 

echo $product_id['products_id'];

 

 

And that gives the right output....... Thanks a million For yout help!

 

:thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup:

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...