Tuesday, August 21, 2018

How to enable CSS Preprocessor SASS/SCSS in Angular 6

11:22:00 AM 2
To enable CSS Preprocessor SASS/SCSS in Angular 6 project, we have update the config file (angular.json) or we can do it by Angular-CLI

By default, if we run ng new project-name using terminal/cmd, the angular framework will be installed without enabling CSS Preprocessors in angular. To overcome this, follow the simple procedure shared below

Scenario 1: ( Enabling SASS/SCSS in existing Angular project )
Using Angular-CLI
  • ng config schematics.@schematics/angular:component.styleext scss  

Manually
  1. Open angular.json file 
  2. Find "schematics": {} 
  3. Add "@schematics/angular:component": { "styleext": "scss" }  

After enabling CSS Preprocessor, just do following steps
  1. Update all .css files to .scss (style.css in src folder and all custom generated components etc..)
  2. Open angular.json file 
  3. Update all "src/styles.css" to "src/styles.scss" Stop the server and restart.. All set to go with SCSS. 

Scenario 2: ( Enabling SASS/SCSS in new Angular project )
Using Angular-CLI 
Add --style=sass with the command to create new angular project ng new project-name --style=sass

Tuesday, July 17, 2018

Find and replace text or link in all the wordpress posts and pages

5:46:00 PM 0
Searching and replacing contents in all the wordpress posts and pages is an easy task. You can use either plugin or manually using SQL query. In this article, we will let you know the SQL query to find and replace particular text or word from wp_posts, wp_postmeta tables
Find and replace in wordpress Posts and Pages
Find and replace in wordpress Posts and Pages

Before starting the find and replace in wordpress posts and pages task, take backup of entire website database. If you are good in SQL, then take backup of wp_posts and wp_postmeta tables alone

You can use following queries to update all the http requests to https after installing SSL certificate

Syntax

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'Text to Find', 'Text to Replace');

Query

UPDATE wp_posts SET post_content = replace(post_content, 'Text to Find', 'Text to Replace');
UPDATE wp_posts SET guid = replace(guid, 'Text to Find', 'Text to Replace');
UPDATE wp_postmeta SET meta_value = replace(meta_value,  'Text to Find', 'Text to Replace');

Friday, July 13, 2018

Laravel Case Sensitive Query

5:05:00 PM 1
PHP Laravel is one of the popular PHP frameworks. It has many inbuilt functions to reduce developers efforts while developing projects. To perform case sensitive search in laravel, there is no inbuilt function provided as of Laravel 5.6. So, now how we do it ?.

user_table
id name
1 Eshin
2 Jozer
3 W3schools100

We have to use MySql function BINARY in where clause to perform case sensitive querying. The MySql example is,

SELECT * FROM 'user_table' WHERE BINARY 'username' = 'W3schools100';  

So how we do in Laravel
We have to add DB::raw() raw query to make case sensitive query. For example

DB::table('user_table')->where(DB::raw("BINARY `username`"),'W3schools100')->get();
or
DB::table('user_table')->whereRaw("BINARY `username` = 'W3schools100'")->get();

Tuesday, July 3, 2018

Bootstrap show/open tabs based on url hash

6:30:00 PM 0
Bootstrap tabs can be switched based on url hash. Bootstrap has provided a jQuery method to open/show tabs programmatically. As we know manual selection of tabs will display appropriate content associated with that particular tab, but to open bootstrap tabs based on url hash follow this blog post by w3schools100

How to add URL hash with a tag

To add URL hash with anchor tag. just append hash value at the end of URL. Example https://w3schools100.blogspot.com/#myCustomHash

Get URL hash using javascript

The syntax to get URL hash is window.location.hash;. By using this, we can identify which tab to be opened.

Open bootstrap tab by jQuery

To open bootstrap tab by the function provided by bootstrap javascript, use $('.nav-tabs a[href="#myCustomHash"]').tab('show'). How to open bootstrap tab by URL hash - Example

How to open bootstrap tab by URL hash - Example

var hash = window.location.hash;
if(hash != '' || hash != undefined)
$('ul.nav a[href="' + hash + '"]').tab('show');

Monday, June 11, 2018

Make youtube video iframe full width 100% to container and height | Responsive Youtube Player

10:01:00 AM 0
Youtube is providing easiest way to embed videos using iframe. For fixed height and width, this works fine. But for responsive designs, we have to do some CSS tricks. Lets go and learn the magic to make youtube video player responsive.


Youtube Responsive Video Player - HTML


 <div id="video-wrapper">
  <iframe width="560" height="315" src="###" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
 </div>


Youtube Responsive Video Player - CSS


 #video-wrapper {
     position: relative;
     padding-bottom: 56.25%; /* 16:9 */
     height: 0;
 }
 #video-wrapper iframe {
     position: absolute;
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
 }

Thats it guys. Simple right ?. Work on it and leave your valuable feedback on comments section.

Popular  searches for this thread
  • Displaying a YouTube video with iframe full width of page
  • How To Make a Responsive 100% Width YouTube iFrame Embed
  • Embed a video at 100% width and keep aspect ratio?
  • Responsive youtube player html
  • Youtube iframe player responsive

Thursday, May 17, 2018

How to create a sticky notification bar on top of the website using CSS

7:03:00 PM 1
Creating sticky hello bar is a very easy task. Just css is enough make this. On page scroll, it will be stick at the top of website. This type of notification bars are also call as top fixed bar for website
Sticky bar Using CSS
Sticky bar Using CSS

Copy following html, css codes and paste it below body tag of your website. That's it, you are done. Very easy right ?. Work on it and let us know your feedback via comments.

Note: Overflow: hidden should not be given to parent elements


HTML Code : Add it below body tag of you website


    <div id="sticky_bar">
        <div id="sticky_bar_text">
            Your notification goes here ..
        </div>
        <div id="sticky_bar_btn">
            <a target="_blank" class="btn" href="#">Sample Button</a>
        </div>
    </div>


CSS Code


#sticky_bar {
    padding: 8px 5px;
    background: #222;
    position: sticky;
    position: -webkit-sticky;
    top: 0;
    z-index: 999;
    text-align: center;
    box-shadow: 0px 1px 11px #888888;
    color: #fff;
    font-family: 'Viga', sans-serif;
    font-size: 1.1em;
}
#sticky_bar_text, #sticky_bar_btn {
    display: inline-block;
}
#sticky_bar_btn a {
  background:red;
  color:#fff;
  padding:2px 5px;
  text-decoration:none;
  border-radius:3px;
}


Demo



Search Keywords
  • Website top sticky bar 
  • Simply sticky hello bar
  • Fixed Notification bar for website
  • Sticky bar in html
  • Sticky bar css
  • Fixed bar on top of website

Friday, February 17, 2017

Select2 autocomplete dynamically from server based on input

12:53:00 PM 0
Select2 is one of the best libraries to add in the sections where to need a textbox autocomplete options. Many entry level developers feel easy to do static autocomplete feature but they feel difficult to add dynamic values in select box. 
Select2 dynamic autocompete
Select2 dynamic autocompete
Here we are going to give code to get get dynamic values in the select2 selectbox based on the input given in select2 textbox. 

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet"></link>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
 
<script>
  $("#select_box_id").select2({
    ajax: {
      url: "server page link",
      dataType: 'json',
      delay: 250,
      data: function (params) {
        return {
          campaign_name: params.term, // search term
        };
      },
      processResults: function (data, params) {
     var values = [];              
     $.each(data, function (key, val) { 
      if(val._id != '')
      {
        values.push({
         id: val.id,
         text: val.campaign_name
        });
      } 
     }); 
     // Sample json data -> [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }]
        return { 
          results: values, //appending values from server to options tag
        };
      },
      cache: true
    },
    escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
    minimumInputLength: 2,
  });
</script>
If you have any doubts, feel free to share below.. We will respond as soon as possible.

Friday, November 11, 2016

How to implement Oauth 2.0 [bshaffer] in Laravel framework

6:23:00 PM 0
Install the OAuth2 server and HTTP Foundation bridge dependencies using Composer:
  • composer require bshaffer/oauth2-server-php and
  • composer require bshaffer/oauth2-server-httpfoundation-bridge
Setup your database and run the provided migration Download migration from the link given below and add it in database.( https://github.com/julien-c/laravel-oauth2-server/commit/b290d4f699b9758696444e2d62dd82f0eeedcb7d) (php artisan db:migrate)

Seed your database using the provided script : Download test database contents from the link given below and add it in tables. (https://github.com/julien-c/laravel-oauth2-server/commit/8895c54cbf8ea8ba78aafab53a5a0409ce2f1ba2 ) (php artisan db:seed)

Setup your OAuth2 server: To be able to access the single instance anywhere in your Laravel app, you can attach it as a singleton:
  • Add the code give below in App Service Provider file. ( app->providers->AppServiceProvider.php ) or create a new service provider and add it.
public function register()
{
     App::singleton('oauth2', function()
     {
          $storage = new OAuth2\Storage\Pdo(array('dsn' => 'mysql:dbname=laravel_test;host=localhost', 'username' => 'root', 'password' => ''));
          $server = new OAuth2\Server($storage);

          $server->addGrantType(new OAuth2\GrantType\ClientCredentials($storage));
          $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));
          $server->addGrantType(new OAuth2\GrantType\RefreshToken($storage));

     return $server;
     });
}} 
To generate & regenerate token :
  • Add the code give below in routes file
Route::post('oauth/token', function()
{
    $bridgedRequest  = OAuth2\HttpFoundationBridge\Request::createFromRequest(Request::instance());
    $bridgedResponse = new OAuth2\HttpFoundationBridge\Response();
  
    $bridgedResponse = App::make('oauth2')->handleTokenRequest($bridgedRequest, $bridgedResponse);
  
    return $bridgedResponse;
});
Parameters used to generate token:

URL : http://localhost:8000/api/oauth/token

Headers Parameters:
  • Authorization → Basic dGVzdGNsaWVudDp0ZXN0cGFzcw== [ Basic base64_encode(client_id:client_password) ]
Body Parameters:
  • grant_type → password
  • username → user's name
  • password → user's password
Sample Result :
{
"access_token": "9cf3edc9f6d7437712a0f344872b04641eb336eb",
"expires_in": 3600,
"token_type": "Bearer",
"scope": null,
"refresh_token": "5d975d306fb0c28813caf2c79916890a2f4dbfe4"
}

Parameters used to re-generate token:

URL : http://localhost:8000/api/oauth/token

Headers Parameters:
  • Authorization → Basic dGVzdGNsaWVudDp0ZXN0cGFzcw== [ Basic base64_encode(client_id:client_password) ]
Body Parameters:
  • grant_type → refresh_token
  • refresh_token → refresh token stored in oauth_refresh_tokens table
Sample Result :
{
"access_token": "205edda287528d136d2ec0be32d8b5e1b572cc77",
"expires_in": 3600,
"token_type": "Bearer",
"scope": null
}

To authenticate token and to get token details (Authentication Server):
  • Add the code give below in routes file
Route::get('private', function()
{
 $bridgedRequest = OAuth2\HttpFoundationBridge\Request::createFromRequest(Request::instance());
 $bridgedResponse = new OAuth2\HttpFoundationBridge\Response();
  
 if (App::make('oauth2')->verifyResourceRequest($bridgedRequest, $bridgedResponse)) {
  
 $token = App::make('oauth2')->getAccessTokenData($bridgedRequest);
  
  return Response::json(array(
   'private' => 'stuff',
   'user_id' => $token['user_id'],
   'client' => $token['client_id'],
   'expires' => $token['expires'],
   ));
 }
 else
 {
  return Response::json(array(
   'error' => $bridgedResponse->getParameter('error'),
   'error_description' => $bridgedResponse->getParameter('error_description'),
   ), $bridgedResponse->getStatusCode());
 }
});

Parameters used to authenticate token:
 
URL :
http://localhost:8000/api/ private


Headers Parameters:
Authorization → Bearer 9b50c978cca15802000beaf13ef95c33e14f1a81 [Bearer Token]
{
"private": "stuff",
"user_id": "bshaffer",
"client": "testclient",
"expires": 1478822036
}

Tuesday, September 20, 2016

Case Sensitive login in codeigniter

7:48:00 PM 0
How to implement case sensitive user login in codeigniter ?. This is the topic we are gonna to see today. Implementing login with case sensitive option in codeigniter is very easy. That is, we need to give 'LIKE BINARY' after the database field name in model query.

Case Sensitive login in codeigniter
Case Sensitive login in codeigniter

Lets see the example codeigniter controller and model codes to that are used to get case sensitive user data from database.

Controller Code:


<?php

function login_controller()
{
 $email = $this->input->post('email');
 $password = $this->input->post('password');
 
 if($email && $password)
 {
  $query = $this->user_model->login_model($email,$password);
  if($query)
  {
   echo "Login Success..";
  }
  else
  {
   echo "Login Failed..";
  }
 }
}
?>

Model Code:

function login_model($email,$password)
{
 $this->db->select('*');
 $this->db->from("user_account");
 $this->db->where("email",$email);
 $this->db->where("password like binary",$password);
 $query = $this->db->get();
 if($query->num_rows() > 0)
 {
  return $query->result();
 }
return false;
}

The main thing used here is $this->db->where("password like binary",$password);

Search Keywords
  • Case sensitive password check in codeigniter
  • Codeigniter case sensitive query
  • Codeigniter Binary query

Jquery copy to clipboard - ctrl + c event

6:59:00 PM 0
Jquery copy to clipboard. How to copy a texbox or textarea content to clipboard using jquery. Here you will get exact result for this question. By using the below code, you can perform "ctrl + c" keyboard event automatically when a user hits a button. Lets see copy to clipboard jquery example
Jquery copy to clipboard - ctrl + c event
Jquery Control + C

Jquery copy to clipboard - ctrl + c code:


<input id="input_textbox" type="text" value="w3schools100" />
<button id="copy_but">Copy to clipboard</button>
 
<script>
    var input = document.getElementById("input_textbox");
 
    $("#copy_but").click(function(event){
        event.preventDefault();
        input.select();
        document.execCommand("copy");
    });
</script>

Search keywords: 
  • How to copy textbox contents using jquery
  • Jquery copy text to clipboard
  • Copy text box contents on a button click
  • How to trigger ctrl + c event  via code

Monday, July 25, 2016

Dim the whole page and show loading image on button click

6:15:00 PM 0
How to grey out or dim the whole page and display loading image on the center of the page, when user clicks a button ?. Most of the programmers uses ajax to request data processing. Some requests may take more time and some will take less time. As they are processing using ajax method, page won't  be refreshed or default loading button in the browser too wont work. So when user clicks a button, and if the request is in progress, we have to display a loading image to notify the users that request is in progress.

show loading image on button click
Show loading image on button click

To implement this loading image feature in your project copy the codes given below and use it in appropriate places.


/* Absolute Center Spinner */
.loading {
  position: fixed;
  z-index: 999;
  height: 2em;
  width: 2em;
  overflow: show;
  margin: auto;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
 
/* Transparent Overlay */
.loading:before {
  content: '';
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.2);
}
 
/* :not(:required) hides these rules from IE9 and below */
.loading:not(:required) {
  /* hide "loading..." text */
  font: 0/0 a;
  color: transparent;
  text-shadow: none;
  background-color: transparent;
  border: 0;
}
 
.loading:not(:required):after {
  content: '';
  display: block;
  font-size: 10px;
  width: 1em;
  height: 1em;
  margin-top: -0.5em;
  -webkit-animation: spinner 1500ms infinite linear;
  -moz-animation: spinner 1500ms infinite linear;
  -ms-animation: spinner 1500ms infinite linear;
  -o-animation: spinner 1500ms infinite linear;
  animation: spinner 1500ms infinite linear;
  border-radius: 0.5em;
  -webkit-box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.5) -1.5em 0 0 0, rgba(0, 0, 0, 0.5) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
  box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) -1.5em 0 0 0, rgba(0, 0, 0, 0.75) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
}
 
/* Animation */
 
@-webkit-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-moz-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@-o-keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
@keyframes spinner {
  0% {
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
</style>
 
<span id="spinner"></span>
 
<script>
function spinner()
{
$("#spinner").html("<div class='loading'>Loading…</div>");
// To stop spinner, $("#spinner").html("");
}
</script>
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
 
<button onclick="spinner()">Test Spinner</button>

(Press F5 to stop the spinner..)

Wednesday, July 13, 2016

How to send emails with HTML page/template in codeigniter

5:07:00 PM 0
Codeigniter allows programmers to send HTML file as an email. This helps to send emails using codeigniter in a good formatted and stylish method. Below we have given codes to send HTML pages along with email in codeigniter. Just run it and comment your view below.
codeigniter send email using html template
codeigniter send email using html template

How send emails in codeignter using email templates?

Controller:

public function test_email()
{
        $this->email->set_mailtype("html");
 $this->email->from('noreply@w3schools100.in', 'W3Schools100');
 $this->email->to('receiver@gmail.com');
 $this->email->subject('Subject');
     
 $mail_data['subject'] = 'Email Subject';
 $mail_data['description'] = "Email body contents..Here you can use HTML tables to format your data..And use \n to print date in a new line"

 $message = $this->load->view('email_page', $mail_data, true);
 $this->email->message($message);
 $this->email->send();
} 
View: -> email_page.php

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"></link>
  <style>
    /* Remove the navbar's default rounded borders and increase the bottom margin */ 
    .navbar {
      margin-bottom: 50px;
      border-radius: 0;
    }
    
    /* Remove the jumbotron's default bottom margin */ 
     .jumbotron {
      margin-bottom: 0;
    }
   
    /* Add a gray background color and some padding to the footer */
    footer {
    background-color: #37454D;
    color:#fff;
      padding: 10px;
    }
  </style>

  <div style="background-color:lightgrey" class="text-center">
  <!-- Give full URL -->
  <img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx53RKF84Qif07L__NTVulVu26pHAP9ZSK4wrLupufXv_1rhtzzfjJOFA79ZiM-dLoe6HRtY2gFl9v5UkKJ9UlynyLJTwmRlGBG6PfyJH-O4qoYc2xlp5vCTFeUQoTrv2kYDuv6LXovUNZ/s1600/SB100+copy.png" class="img-responsive" alt="StudentsBlog100" title="Studentsblog100"/>
  </div>

<div class="container">    
  <div class="row">
    <div class="col-sm-12">
     <h3 style="font-weight:bold"><?php if(isset($subject)) { echo $subject; }?></h3>
     <p><?php if(isset($description)) { echo $description; }?></p>
    </div>
  </div>
</div>

<footer class="container-fluid text-center">
  © W3schools100
</footer>
codeigniter send email using html template

  • codeigniter send email html format
  • mail codeigniter 

Friday, June 3, 2016

HOW TO PRINT/ECHO/WRITE ARRAY VALUES IN FILE - PHP

4:25:00 PM 0
Generally it is very easy to write some string in file using php. But some times, we may required to write arrays in file using php. The situation may arise when we required to check API input values, post method values etc..
HOW TO PRINT/ECHO/WRITE ARRAY VALUES IN FILE
Add HOW TO PRINT/ECHO/WRITE ARRAY VALUES IN FILE

General method to write string in php is,
$text = "Hai how are you";
file_put_contents("test.txt",$text);
After executing above code, you will get an output as "Hai how are you" in the file.

How to write array values in a file?

$a = array('1','2','3','4','5');
file_put_contents("test.txt",print_r($a,true));
Execute above code and see the array values printed in the file. If you have any queries or suggestion related this post, feel free to comment below.

Monday, April 11, 2016

How to use or_like and where condition in codeigniter query builder

6:49:00 PM 0
As we know, codeigniter query builder is one of the easiest method to create database queries. But in some complex situations it is not giving exact results. If codeigniter got upgraded, this type of errors will be solved, but it was not upgraded for many years. Anyhow today we are going to see about "How to use or_like and where condition in codeigniter"
or_like and where condition in codeigniter
or_like and where condition in codeigniter

or_like and where condition in codeigniter

Table name : items
idNameTypeCountry
1BananaFruitIndia
2CarrotVegetablePakistan
3AppleFruitUSA
4TomatoVegetableUAE
5OrangeFruitIran
6cucumberVegetableIndia

Consider above table "items". Now you need to search a data from name and country fields, where type =  Fruit. In this case use following code to get exact result from codeigniter.

public function search_items($search_keyword="") {
    $this->db->select('*');
    $this->db->from('items');
    $where = "type = 'Fruit' AND (name LIKE '%$search_keyword%' OR country LIKE '%$search_keyword%')";
    $this->db->where($where);
    $query = $this->db->get();
    if($query->num_rows() > 0) {
        return $query->result();
    }
    return false;
}
Try this and if you have any doubts or any alternative solutions, please comment below. Thank you - W3schools100 Team

Tuesday, April 5, 2016

Codeigniter godaddy hosting error - No input file specified.

6:42:00 PM 0
Usually while developing any php applications using codeigniter framework, developers used to remove index.php from the codeigniter default url by using .htaccess file. And it will work perfectly in local machine. And after uploading all the codeigniter files in godaddy server, some times it wont work properly and it shows and error "No input file specified." To avoid this type of errors, we have added a htaccess file. Just check it and comment below.
Codeigniter godaddy hosting error - No input file specified
Codeigniter godaddy hosting error - No input file specified

How to overcome "No input file specified." godaddy codeigniter error ?

Here we have a solution,

Step 1
  1. Create a file in codeigniter main (root) folder.
  2. Copy paste below given codes
  3. Finally save it as .htaccess (without any name in front of .)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Step 2
  1. Open application->config->config.php
  2. Find " $config['index_page'] " and " $config['uri_protocol'] " code from the config.php file and give the value as given below.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

That's all, now your codeigniter application will run perfectly with godaddy hosting. If you have any queries, please comment below. We will help you as soon as possible.

Search tags:
codeigniter godaddy remove index php

codeigniter htaccess remove index php godaddy
codeigniter htaccess remove index.php not working
no input file specified codeigniter godaddy
no input file specified codeigniter htaccess
codeigniter mod_rewrite no input file specified

Tuesday, March 29, 2016

Textbox autocomplete using jquery - html5 datalist alternate method w3schools100

5:16:00 PM 0
Autocomplete textbox values by using HTML5 datalist method is an easy way to implement autocomplete function in textboxes. But the problem is, it wont work in safari browser and inner word search feature is not working in google chrome web browser.

So, we must need an alternative method to implement autocomplete textbox values. Here we are going to see, how to implement autocomplete in jquery. If you have basic working knowledge in jquery, you can easily get perfect output by using our sample code.

External files we required are,
  • jquery.min.js  (Jquery library)
  • jquery-ui.js  (Jquery autocomplete)
  • jquery-ui.css  (Jquery autocomplete CSS)
Complete code

<html>
<head>
<title>Jquery autocomplete textbox</title>

<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<script>
$(function() {
 // SAMPLE ARRAY
 var arrLinks = [ 
   { id: 1, url: "http://w3schools100.blogspot.com", label: 'W3schools' },
   { id: 2, url: "http://studentsblog100.blogspot.com", label: 'StudentsBlog100' },
   { id: 3, url: "http://samplesite.com", label: 'Sample Site'} 
         ];
 //AUTOCOMPLETE FUNCTION    
 $("#text_box_id").autocomplete({
 source: arrLinks,
 messages: {
 noResults: '',
 results: function() {}
 }
 });
  
 /*AUTO COMPLETE - AFTER SELECT START*/
 $("#text_box_id").on("autocompleteselect", function (e, ui) {
 // e.preventDefault(); // prevent the "value" being written back in text box.
 
 var id = ui.item.id; //id,label,url etc..
 alert(id);

 });
 /*AUTO COMPLETE - AFTER SELECT END*/
});
</script>
</head>

<body>
Enter Keyword : <input id="text_box_id" type="text" />
</body>

</html>
Output
Textbox autocomplete using jquery w3schools100
Textbox autocomplete using jquery w3schools100

Thursday, March 24, 2016

Joining two tables in codeigniter query

6:52:00 PM 1

How to join two tables in codeigniter ?

Codeigniter table joining queries are used to join two database tables. Most of the php web developers know to join mysql database tables using core php but not by using codeigniter query builder. So, today we are going to discuss about joining two tables in codeigniter with examples.
How to join two tables in codeigniter
Codeigniter table join

Consider two database tables 
1)  students_account - To store students details.
2)  school_list - To store school details.

Table 1 : students_account
idstudent_nameschool_id
1Eshin3
2Jozer1
3Jacinth2
Table 2 : school_list
idschool_name
1StudentsBlog100
2W3schools100
3Sample School

Model

function test_model($student_id)
{
     $this->db->select('students_account.*,school_list.school_name');
     $this->db->from("students_account");
     $this->db->join('school_list', 'students_account.school_id = school_list.id', 'left');
     $this->db->where("students_account.id",$student_id);
     $query=$this->db->get();
          if($query->num_rows() > 0)
          {
          return $query->result();
          }
     return false;
}

Controller

public function test_controller() 
{
     $student_id = 2;
  
     $query = $this->model_name->test_model($student_id);  
          if($query)
          {
               echo "<pre>";
               print_r($query);
               echo "</pre>";
          }
          else
          {
               echo "problem in getting student's details";
          }
 }

Test by using above sample codes.. if you have any doubts or any mistakes in the codes given above, please let me know by commenting below.. Thank you, W3schools100 team