Skip to main content

ionic cordova run not detecting device and starts emulator

While running “ionic cordova run“, I experienced that app did not run on device and started on emulator.

If this is the case with you too, first check whether your machine(PC) is detecting the connected device(phone) or not.

Basic steps for making ” ionic cordova run ” to run app on device

Run the following command “adb devices -l“. If it does not show any device attached, then make sure your phone’s USB Debug mode is “enabled” and Developer mode is turned “On”. Also, your USB Options is set to “Transfer media files”.

In my case, Developer mode was not turned on. After turning it on, “adb devices -l” was able to detect my device.

ionic cordova run

According to official documentation of ionic, we need to execute the following command in order to run the app on our device

” ionic cordova run android –device”


Some important reference links are:

Relevant post from Ionic official doc

Relevant post from Ionic-framework forum


Orders count of product in Opencart

While developing e-commerce website I came across adding a feature to display total orders count of product in OpenCart on product’s page. This way visitors will be able to know about how much orders of a specific product have been given (my client’s perspective). Since OpenCart follows MVC architecture, therefore the developer experienced with MVC architecture and especially with Codeigniter can easily understand and follow the modifications described below.

  1. We are required to add a function in the product’s Model for fetching orders count of a product.
  2. Gather the required info from Model into Controller
  3. Display the info on view page of product

Code for displaying Orders count of product in Opencart

In Model folder, find product.php file and add the following function/code. This code contains required query for getting orders count of product.

I found required file in > (catalog/model/catalog/product.php)

public function getOrdersCount($product_id){
		$sql = $this->db->query('SELECT COUNT(order_id) as total_orders 
                        FROM '.DB_PREFIX.'order_product 
                        WHERE product_id = ' . $product_id);
        return $sql->rows[0]['total_orders'];

In Controller folder, find product.php file and add following statement in its index() function.

I found required file  in(catalog/controller/product/product.php)

$data['total_orders'] = $this->model_catalog_product->getOrdersCount($product_id);

We are now done with backend code and left with front-end for display of counter. Open your theme folder and find product template file(product.tpl).

product.tpl (catalog/view/theme/your_theme/template/product/product.tpl)

Its now all about HTML for displaying required info according to your template.

<div class="total_orders">
					<h3>Total Orders</h3>
						echo $total_orders;

So this is it, all done. These were three simple steps for a web developer to add a functionality for displaying orders count of product in OpenCart.

setTimeout function jQuery

If you are thinking to perform some operation(s) after some specified interval of time, then jquery setTimeout function is ready to do the job for you.

setTimeout function

setTimeout() accepts two arguments.

  1. The function that you want to execute after specified delay.
  2. The duration of delay in milliseconds
var myFunction = function(){
			alert('Hello World!');

		setTimeout(myFunction, 2000);

In the above example code, myFunction is the one which I wanted to execute after 2 seconds.

In another way, one can also use anonymous function(if not want to define the function separately) and define login in setTimeout as follows:

			alert('Hello World');
		}, 2000);

setTimeout() is a basic JavaScript function, actually. Do not confuse setTimeout() with setInterval() function. The difference between the two is that setTimeout() executes once after specified time, while setInterval() repeats the execution of function.

Send email using PHP script

A basic and simple article for the beginners who want know about how to to send email using php.

In this article, we will use HTML form to get data from the user and send an email using PHP script. PHP mail() function is used to send an email. We can send both simple/text emails and also HTML emails. First, we will learn about how to send email using PHP.

HTML form

Following is the HTML form which will be used to fill the required data.

<form action="process_email_form.php" method="post">
		<label for="name"></label>
		<input type="text" name="name"><br>

		<label for="email"></label>
		<input type="email" name="email"><br>
		<label for="subject"></label>
		<input type="text" name="subject"><br>
		<label for="message"></label>
		<textarea name="message" id="" cols="30" rows="10"></textarea><br>

		<input type="submit" value="Send Email">


Send email using php

Following is the script which will be used to send an email using PHP. Create new file named as “process_email_form.php” for script.

    $name = $_POST['name'];
    $email = $_POST['email'];
    $subject = $_POST['subject'];
    $message = $_POST['message'];
    ===================== perform check if any field in form is empty
    if(empty($name) || empty($email) || empty($message) || empty($subject)){
        echo "Kindly fill all the fileds";
    // change the following statement according to your need.
    $to = "";

    if(mail($to, $subject, $message)){
        echo "Message Sent!";

The above script initially get the form data and then applies check on them if any field was left empty. Finally, mail() function is used in order to send email using php script.

This was all about sending simple text email and using mail() function. You can play with the code to add validation and error checks.

Next article will be about sending HTML email in PHP.

Other related articles:

use php mail functions to send email



Get URL parameter using jQuery

With the help of jquery we can easily extract or get URL parameter. This post contains the jquery code which can be used to get URL parameter.

jQuery Script to get URL parameter

		function getUrlParameter(search_param){
			// get string of paramters
			var url_part =;
			// decode string
			var decoded_url_part = decodeURIComponent(url_part);
			// split on the basis of "&"
			var params = decoded_url_part.split('&');
			//iterate throw each param and find if it matches required component
			for(i = 0; i < params.length; i++){
				param = params[i].split('=');
				if(search_param == param[0]){
					return param[1];
			// console.log(splitted);
		var message_param = getUrlParameter("message");

This script will help you in extracting the required parameter from URL. The function getUrlParameter() is responsible for extracting parameters from URL and returning the value of required paramater, if found.


For example, you have the following URL

Now you want to find message and its value. Call the function getUrlParamter() and pass the string “message”. The function will extract parameters from current URL will match “message” will each. A value will be returned if “message” parameter is found.


select one element from same class using jquery

At times, you may come across a situation when you need to select one element from same class. jQuery makes is very simple to select an element from same class.

Lets setup an example of five paragraph which share same class.

<p class="para">Hello, I am a paragraph</p>
<p class="para">Hello, I am a paragraph</p>
<p class="para">Hello, I am a paragraph</p>
<p class="para">Hello, I am a paragraph</p>
<p class="para">Hello, I am a paragraph</p>

Now, we want to change the color of third paragraph, only. Following script will work for us.


:eq() is one of the index-selectors. Other index-selector are :lt() :gt() :odd() :even. Try to play with them ,too.



eq-selector @


Download file using jQuery / JavaScript

In this article, we will share a simple script about how to download file using jQuery or JavaScript. Example will focus on jQuery click event.

Suppose we have a button or a link which has id=”download_file”.

<a href="#" id="download_file">
Download File


We want to download the file when a user clicks on this button.

<script type="text/javascript">
    $('#download_file').click(function(e) {
        e.preventDefault();  //stop the browser from following'files/my-file.pdf');  


This is a very simple script about how to download file using jQuery / JavaScript.



jQuery click not working on dynamic content [solution]

jQuery click not working? Follow this article to find a solution.

Sometimes you may come across an issue where jquery event does not work on an element, which is generated dynamically via jQuery. For example, if you have any HTML element on which you click to create/append some other HTML element, jQuery click will not work on the appended or dynamically created element on the page.

If the code is not working on dynamically created content, the code might be as follows.

     //required logic

.class_name is actually the name of class of the element that was generated by jQuery, dynamically.

In such case, you will have to modify your code a bit in the following way.

$(document.body).on('click', '.class_name' ,function(){
     // required logic

This change in code has always worked for me whenever I wanted to trigger a function on the event or simply click event upon dynamically created content. I hope this will work you, too.

For further study:

Jquery event handler not working on dynamic content

Multiple filters with ngRepeat in AngularJS

In this article with will learn how to use multiple filters with ngRepeat in AngularJS. Our example will focus on filtering the data produced from ng-repeat by using multiple filters.

Let’s suppose we have the following data in JSON.

var app = angular.module('app',[]);

app.controller('EmployeeCtrl', function ($scope) { 
 $scope.employee = [{
 name: 'Andrew',
 district: 'Islamabad' 
 }, {
 name: 'Will',
 district: 'Peshawar'
 }, {
 name: 'Mark',
 district: 'Peshawar'
 }, {
 name: 'Alice',
 district: 'Islamabad'
 }, {
 name: 'Todd',
 district: 'Peshawar'
 }, {
 name: 'Todd',
 district: 'Islamabad'
 }, {
 name: 'Tom',
 district: 'Peshawar'
 }, {
 name: 'Aliza',
 district: 'Peshawar'
 }, {
 name: 'Todd',
 district: 'Peshawar'
 }, {
 name: 'Todd',
 district: 'Islamabad'

Now printing the data with ng-repeat in HTML part of code.

<body ng-app="app">
 <div ng-controller="EmployeeCtrl">
 <li ng-repeat="e in employee">
 {{ }} - {{e.district}}
 <script src="js/angular.min.js"></script>
 <script src="js/app.js"></script>

Adding multiple filters with ng-repeat. Modify the above HTML code as follows.

<body ng-app="app">
 <div ng-controller="EmployeeCtrl">
 <input type="text" ng-model="searchName">
 <input type="text" ng-model="searchDistrict">
 <li ng-repeat="e in employee | filter:{name:searchName, district:searchDistrict }">
 {{ }} - {{e.district}}
 <script src="js/angular.min.js"></script>
 <script src="js/app.js"></script>

At this point, we have added two (multipe) filters with ng-repeat. For example, if user types “to” in the name field and “is” in district field, then this will act like AND condition as selecting those records in which name inlucdes “to” and district includes “is”.

This is how easily we have added multiple filters with ngRepeat.

Remove WordPress version information

You may come across some different ways of removing WordPress version from the head tag. The preferred way of how to remove WordPress version from the head tag is mentioned in this article. The reason to be preferred is that it will remove WordPress version information from both site and RSS feeds.

Within your themes folder, open functions.php file and paste the following code.

Preferred way of how to remove WordPress version info

function rem_wp_ver(){
  return '';
add_filter('the_generator', 'rem_wp_ver');

This is how you can remove WordPress version information not only from the site but from all the locations.