Skip to main content

Posts

Showing posts from January, 2010

Oscommerce - Dont show latest products at the bottom

In Oscommerce, generally the latest products (which may be added/edited) are shown at the bottom of the categories page, below the sub categories. To avoid this, simply comment the code in the while loop of the file: includes/modules/new_products.php The code will be something like: while ($new_products = tep_db_fetch_array($new_products_query)) { ..... Now you dont find any single products when you open a category.

Fetch data by functions

If you are a hard coder, you might write hundreds of lines of php code to fetch the data from database, to show it in the form. But it may eat up lots of time and also costs the energy of your fingers. Why not we use the php functions to fetch the data and avoid rewriting of the code? Suppose we want to display the information of a product based on the category it belongs to. For this, we write a query like: select * from products where category_id=1 and product_id=2. This will fetch the details about a product with id=2(say, Reynolds) and category with id=1(say, Pens). Then we can fetch the Reynolds product data and display it as needed. But suppose you need to fetch the details of the Reynolds product often and display it. Its not easy for a common developer to write queries now and then to fetch 1 or 2 columns of data (say, we just need the price and color). Then we can use custom php functions to get the work done. For ex, i frequently need to fetch the price of a product, and disp

pass parameters by id in url

When you are passing parameters in the url, remember to pass the parameters by their id, not value. It would be better. For ex, if you have to pass the "city" parameter to a file called index.php, do pass it as: index.php?city=2, not like index.php?city=bangalore It would be readable and also easy to use the values in our queries, with out much validations. (probably only integer validation is needed!) Especially when we are using ajax calls, this is useful.