Tuesday, March 27, 2018

Multiply 2 columns from same row and sum all the results MYSQL

If we want to multiply 2 columns from same row and then sum all the results in mysql

Here is example table

ProductID Price QTY
1 100 2
1 100 2
2 200 3
1 100 1

 SELECT SUM(price*qty) price, SUM(qty) qty, proID FROM `table1` GROUP BY proID  

Result Will like blew

ProductIDPriceQTY
15005
26003

Sunday, February 25, 2018

Removing file extensions php/html from URL using htaccess

Open your .htaccess file using text Editor option. Then place this code

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html

Now Save the file. Now you'll see extension are gone from URL.

Sunday, January 7, 2018

Arrange your mysql table's primary ID which is auto increment

What if you have a large MYSQL table where you've used auto increment ID but your ID are not arrange as many of your row deleted. In this case if you want to arrange your ID like fresh one so that it may increase your MYSQL performance.

First create a blank duplicate table where no data exist. If new created table name "table1".

Your main table name is "table".

Now run this query

CREATE TEMPORARY TABLE tmp SELECT * FROM table;
UPDATE tmp SET id=NULL;
INSERT INTO table1 SELECT * FROM tmp;
DROP TABLE tmp;

You'll see the new "table1" table copied data from old table with arrange ID. now delete the old table.

That's it. Every easy haaa!!!!




Total Pageviews