Thursday, 18 August 2016

Remove Non numbers in input values in jquery



Remove Non numbers in input values in jquery

if (/\D/g.test(this.value))
{
   
// Filter non-digits from input value.
   
this.value = this.value.replace(/\D/g, '');
}

Friday, 29 July 2016

Get dropdown value, text in jquery

Get dropdown value, text in jquery


jQuery(".cls_name option:selected").attr('name');

jQuery(".cls_name option:selected").text();

Tuesday, 1 December 2015

Remove all characters and spaces form string in php

Remove all characters and spaces form string in php


 $string = 'name @123&';
 
echo preg_replace('/[^A-Za-z0-9\-]/', '', $string)

Friday, 21 August 2015

Multiple File Upload by using Jquery

Multiple File Upload by using Jquery
 
View
<div id="maindiv">
<div id="formdiv">
<h2>Multiple Image Upload Form</h2>
<form enctype="multipart/form-data" action="" method="post">

<div id="filediv"><input name="file[]" type="file" id="file"/></div>
<input type="button" id="add_more" class="upload" value="Add More Files"/>
<input type="submit" value="Upload File" name="submit" id="upload" class="upload"/>
</form>


</div>
</div>

Controller

if($this->input->post('submit'))
{
$filename=$_FILES["file"]["name"];
$temp_file=$_FILES["file"]["tmp_name"];
$Temp_File_Type=$temp_file[0];
if($_FILES["file"]["size"][0] !=0)
{
$type1 = exif_imagetype($Temp_File_Type);

if ($type1 == 1 || $type1 == 2 || $type1 == 3 || $type1 == 6 ) // 1 =GIF, 2 =JPEG, 3 =PNG, 6 =BMP
{
for($i=0; $i<count($filename); $i++)
        {
            $File_Name=$filename[$i];
            $Temp_File=$temp_file[$i];
            $upload_path='temp_upload_images/'.$File_Name;
            move_uploaded_file($Temp_File, $upload_path);
        }
        echo "Image uploaded successfully";
}
}
}

Jquery Script
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="script.js"></script>


<script>
var abc = 0;    
$(document).ready(function() {

$('#add_more').click(function() {
$(this).before($("<div/>", {
id: 'filediv'
}).fadeIn('slow').append($("<input/>", {
name: 'file[]',
type: 'file',
id: 'file'
}), $("<br/><br/>")));
});
// Following function will executes on change event of file input to select different file.
$('body').on('change', '#file', function() {
if (this.files && this.files[0]) {
abc += 1; // Incrementing global variable by 1.
var z = abc - 1;
var x = $(this).parent().find('#previewimg' + z).remove();
$(this).before("<div id='abcd" + abc + "' class='abcd'><img id='previewimg" + abc + "' src=''/></div>");
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
$(this).hide();
$("#abcd" + abc).append($("<img/>", {
id: 'img',
src: 'x',
alt: 'delete'
}).click(function() {
$(this).parent().parent().remove();
}));
}
});
// To Preview Image
function imageIsLoaded(e) {
$('#previewimg' + abc).attr('src', e.target.result);
};
$('#upload').click(function(e) {
var name = $(":file").val();
if (!name) {
alert("First Image Must Be Selected");
e.preventDefault();
}
});
});
</script>


CSS

<style>
#maindiv{
width:960px;
margin:10px auto;
padding:10px;
font-family:'Droid Sans',sans-serif
}
#formdiv{
width:500px;
float:left;
text-align:center
}
form{
padding:40px 20px;
box-shadow:0 0 10px;
border-radius:2px
}
h2{
margin-left:30px
}
.upload{
background-color:red;
border:1px solid red;
color:#fff;
border-radius:5px;
padding:10px;
text-shadow:1px 1px 0 green;
box-shadow:2px 2px 15px rgba(0,0,0,.75)
}
.upload:hover{
cursor:pointer;
background:#c20b0b;
border:1px solid #c20b0b;
box-shadow:0 0 5px rgba(0,0,0,.75)
}
#file{
color:green;
padding:5px;
border:1px dashed #123456;
background-color:#f9ffe5
}
#upload{
margin-left:45px
}
#noerror{
color:green;
text-align:left
}
#error{
color:red;
text-align:left
}
#img{
width:17px;
border:none;
height:17px;
margin-left:-20px;
margin-bottom:91px
}
.abcd{
text-align:center
}
.abcd img{
height:100px;
width:100px;
padding:5px;
border:1px solid #e8debd
}
b{
color:red
}
</style>

Pagination using Jquery in Codeigniter

Pagination using Jquery in Codeigniter


$page=3;
$page_count=10;
$data=array();
$content='<div class="pagiright">
                <ul>';
                if($page>2)
                {
                $content.='<li><a id="page-list" data-value=1>First</a></li>';
                }
                if($page!=1)
                {
                $content.='<li><a id="page-list" data-value='.($page-1).'> < </a></li>';
                }
                if(($page-2)>0)
                {
                $content.='<li><a id="page-list" data-value='.($page-2).'>'.($page-2).'</a></li>';
                }
                if(($page-1)>0)
                {
                $content.='<li><a id="page-list" data-value='.($page-1).'>'.($page-1).'</a></li>';
                }
                $content.='<li><a id="page-list" class="active" data-value='.($page).'> '.$page.' </a></li>';
               
                if(($page+1)<=$page_count)
                {
                $content.='<li><a id="page-list" data-value='.($page+1).'>'.($page+1).'</a></li>';
                }
                if(($page+2)<=$page_count)
                {
                $content.='<li><a id="page-list" data-value='.($page+2).'>'.($page+2).'</a></li>';
                }
                if($page<$page_count)
                {
                $content.='<li><a id="page-list" data-value='.($page+1).'> > </a></li>';
                }
                if($page<$page_count-1)
                {
                $content.='<li><a id="page-list" data-value='.$page_count.'>Last</a></li>';
                }
                $content.='</ul>
            </div>';
            $data['text']=$content;
            $this->load->view('holidays/pagi',$data);
           
CSS

<style>
.pagiright{width: 450px;
    float: left;}
    .pagiright ul{    margin: 0;
    padding: 0;
    float: right;
}
.pagiright li{list-style: none;
    float: left;
    margin-right: 8px;
    cursor: pointer;
    background: none!important;
    border: none!important;
    padding: 0!important;}
    .pagiright li a{text-decoration: none;
    color: #727272;
    font: 12px Arial,Helvetica,sans-serif;
    padding: 5px 12px;
    text-align: center;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    background: #f6f6f6;
    border: 1px solid #e3e3e3;}
.pagiright li a:hover {
    background: #F28D51;
    color: #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 1px solid #e3e3e3;
}
.pagiright li a.active {
    background: #FF5E00;
    color: #fff;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 1px solid #E75222;
}
</style>

Jquery

$.post('controller',{'room_data':rooms},function(data){
   
    location="<?=base_url()?>holidays/holidayInfo/";
    });

Tuesday, 7 July 2015

Codeigniter

Codeigniter

Controller

public function __construct(){
    
     parent::__construct();
   
     $this->load->model('admin_model');
     $this->class = strtolower(__CLASS__);
     $this->page_limit = 20;                        // Setting the number of records per page for Pagination
     $this->load->helper(array('url','form'));
     $this->load->library(array('form_validation','session','parser','pagination'));
   
      $this->load->library("excel");
   
   }


Model:

class Agent_model extends CI_Model{
  
       public function __construct(){
        
         $this->load->database();
       }
}

Thursday, 2 July 2015

Upload CSV file in php

Upload CSV file

             $File_Name=$_FILES['upload']['tmp_name'];

                $fp=fopen($File_Name,'r');

                while($data=fgetcsv($fp))
                {
                    $add_data=array('Name'=>$data[0],'No_of_Nights'=>$data[1])

                 }

Monday, 27 April 2015

get Php, codeigniter versions

echo phpinfo() --- Php information

CI_VERSION ---- codeigniter version


Thursday, 10 July 2014

Sending email to multiple in codeigniter from localhost

Sending email to multiple in codeigniter from localhost


public function mail_send()
{
    $config = Array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => 'xxxx@gmail.com', // change it to yours
  'smtp_pass' => 'xxxx', // change it to yours
  'mailtype' => 'html',
  'charset' => 'iso-8859-1',
  'wordwrap' => TRUE
);

        $message = 'Hi This is Test Mail';
        $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xxxx@gmail.com'); // change it to yours
      $this->email->to(array('xxxx@gmail.com','xxxx1@gmail.com'));// change it to yours
      $this->email->subject('Test mail from BNR');
      $this->email->message($message);
      if($this->email->send())
     {
      echo 'Email sent.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }

}

Friday, 20 June 2014

Select only 3 options in dropdown jquery php

Select only 3 options in dropdown jquery php

<script>

$("#destination_airport").on("change", function()
{
    var msg = $("#msg");
   
    var count = 0;
   
    for (var i = 0; i < this.options.length; i++)
    {
        var option = this.options[i];
       
        option.selected ? count++ : null;
       
        if (count > 3)
        {
            option.selected = false;
           
            msg.html("Please select at most three options.");
        }
    }
});
</script>

Thursday, 19 June 2014

File or Image validation in codeigniter in php

File or Image validation in codeigniter in php


$this->form_validation->set_rules('image','Image','file_required|file_size_max[500]|file_allowed_type[image]');

Wednesday, 18 June 2014

Calender in php

Calender in php, codeigniter

<?
if($_POST)
{
    $day=01;
    $month=$_POST['month'];
    $year=$_POST['year'];
}
else
{
    $day=date('d');
    $month=date('m');
    $year=date('Y');
}

$prev_month=$month-1;
$next_month=$month+1;

$prev_year=$year;
$next_year=$year;

if($prev_month==0)
{
    $prev_month=12;
    $prev_year=$year-1;
}
if($next_month==13)
{
    $next_month=1;
    $next_year=$year+1;
}

$days_to_add=date('N',strtotime(date('l',strtotime($day.'-'.$month.'-'.$year))));

($days_to_add==7) ? $days_to_add=0 : '';

$num_days=date('t',strtotime($day.'-'.$month.'-'.$year));

$weeks=ceil(($num_days+$days_to_add)/7);

$days=array(1=>'Mon',2=>'Tue',3=>'Wed',4=>'Thu',5=>'Fri',6=>'Sat',7=>'Sun');

$date_to_display=1;
echo "<form action='' method='post'> <input type='text' name='month' value='".$prev_month."' hidden/><input type='text' name='year' value='".$prev_year."' hidden/><input type='submit' name='next' value='Prev'/></form> ... <form action='' method='post'> <input type='text' name='month' value='".$next_month."' hidden/><input type='text' name='year' value='".$next_year."' hidden/><input type='submit' name='next' value='Next'/> </form>";

echo "<br><br>Calender for ".date('M',strtotime($day.'-'.$month.'-'.$year))." ,$year<br><br>";
echo "<table cellpadding='3'>";
echo "<tr>";
for($i=1;$i<=7;$i++)
{
echo "<td>".$days[$i]."</td>";
}
echo "<tr>";

for($i=1;$i<=$weeks;$i++)
{
    echo "<tr>";

        for($j=1;$j<=7 && $date_to_display<=$num_days;$j++)
        {
            if($i==1)
            {
                if($days_to_add>1)
                {
                    echo "<td></td>";
                    $days_to_add--;
                }
                else
                {
                    echo "<td>$date_to_display</td>";
                    $date_to_display++;
                }
            }
            else
            {
                echo "<td>$date_to_display</td>";
                $date_to_display++;
            }
        }

    echo "</tr>";
}
echo "</table>";

?>

Saturday, 31 May 2014

sql for get data from data base in codeigniter

public function name()
{
return $this->db->select('*')->from('tablename')->where(condition)->get()->result();
}

Wednesday, 11 September 2013

Enable or Disable Text field when check the check box in php

//Enable or Disable Text field when check the check box in php

<html>
<head>
<title>bnr</title>
<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status;
document.f1.other_text.disabled = status;
}
//-->
</script>
</head>
<body onload=enable_text(false);>

<form name=f1 method=post>
<input type="checkbox" name=others onClick="enable_text(this.checked)" >Others
<input type=text name=other_text>
</form>

</body>
</html>

Enable and Disable submit button when click on radio button

// Enable and Disable submit button when click on radio button



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" onclick="form1.b1.disabled=false" />
      yes</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" onclick="form1.b1.disabled=true" />
      no</label>
  </p>
  <p>
    <input type="submit" name="b1" id="b1" value="Submit"
    disabled="disabled" />
  </p>

</form>
</body>
</html>

Display in Drop down list from mysql database in php

//Display in Drop down list from mysql database in php 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('bnr');

$sql = "SELECT name FROM reg";
$result = mysql_query($sql);

echo "<select name='name'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['name'] ."'>" . $row['name'] ."</option>";
}
echo "</select>";

?>
</body>
</html>

favicon image or title image for html page

//favicon image or title image for html page...

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>BNR</title>

<link rel="icon"
 type="image/jpg"
 href="images.jpg" />

</head>

Monday, 2 September 2013

display image in registration form

//Display Image in Registration Form

//image_form.php

<html>
<body>
<fieldset>
<legend>Customer Details</legend>
<form action="action.php" enctype="multipart/form-data"
method="post">
<table>
<tr>
<td><label>Name:</label></td>
<td><input name="name" type="text" /></td>
</tr>
<tr>
<td><label>Phone No:</label></td>
<td><input name="phone" type="text" id="phone" /></td>
</tr>
<tr>
<td><label>Email Id:</label></td>
<td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><input name="address" type="text" id="address" /></td>
</tr>
<tr>
<td><label>Country:</label></td>
<td><input name="con" type="text" id="con" /></td>
</tr>
<tr>
<td><label>Select your photo:</label></td>
<td><input name="image" type="file" /></td>
</tr>
<tr>
<td><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>

//...............................................................................................................................................
//Action.php

<html>
<body>
<?php
 $sname=$_POST['name'];
 $phone=$_POST['phone'];
 $email=$_POST['email'];
 $address=$_POST['address'];
 $contry=$_POST['con'];
 extract($_FILES['image']);
 /*print_r($_FILES);*/
 if($error==0)
 {
   if(($type="image/jpeg")||$type="image/pjpeg")
   {
    if(($size)/1024<=1000)
    {
     $path="upload";
     $filename=rand(1,1000)."_".$name;
     $act_path=$path."/".$filename;
     copy($tmp_name,$act_path);
     $f=1;
    }
    else
    {
     $msz="its too large! i can't handle it.";
    }
   }
   else
   {
    $msz="Opps! your file is not valid";
   }
 }
else
{
$msz="Error in the file!!";
}
if($f==1)
{
?>
<div style="width:550px;margin:0 auto;
padding:10px;background-color:#69F;
height:130px;box-shadow:#000 0 0 10px;">
<div style="float:right;border:1px solid #ccc;
padding:1px 2px;width:130px;
box-shadow:#aaa 0 0 10px;">
<?php
echo "<img src=\"$act_path\" height=100/>";
?>
</div>
<div style="float:left;padding-right:5px;">
<table style="text-align:left;color:#ffffff;
font-weight:bold;text-shadow:1px 1px #aaa;">
<tr>
<td>Name:</td>
<td style="text-align:left;color:yellow;">
<?php echo $sname; ?></td>
</tr>
<tr>
<td>Phone No:</td>
<td style="text-align:left;color:yellow;">
<?php echo $phone; ?></td>
</tr>
<tr>
<td>Email Id:</td>
<td style="text-align:left;color:yellow;">
<?php echo $email; ?></td>
</tr>
<tr>
<td>Address:</td>
<td style="text-align:left;color:yellow;">
<?php echo $address; ?></td>
</tr>
<tr>
<td>Country:</td>
<td style="text-align:left;color:yellow;">
<?php echo $contry; ?></td>
</tr>
</table>
</div>
</div>
<?php
}
else
{
header("location:image_form.php?data=$msz");
}
?>
</body>

</html>

download image or file from mysql database in php

// Download image or file from mysql database in php(down1).....



<html>
<head>
<title>Download File From MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?php
//database connection
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
//select database
$db = mysql_select_db('bnr1', $con);
$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php echo urlencode($id);?>"
><?php echo urlencode($name);?></a> <br>
<?php
}
}
mysql_close();
?>
</body>
</html>
<?php
if(isset($_GET['id']))
{
// if id is set then get the file with the id from database
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('bnr1', $con);
$id    = $_GET['id'];
$query = "SELECT name, type, size, content " .
         "FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content) = mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
ob_clean();
flush();
echo $content;
mysql_close();
exit;
}
?>

upload file or image into database in php mysql

//Upload file or image into database in php(up1)
//create table as follows..........

<html>
<head></head>
<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td>please select a file</td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE"
value="16000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile'])));
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'root', '') or die(mysql_error());
$db = mysql_select_db('bnr1', $con);
if($db){
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName uploaded<br>";
}else { echo "file upload failed"; }
}
?>
end