Friday, November 17, 2017

core php pagination example

<?php

require_once "config.php";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pagination</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<table style="border: 1px #000000 solid;" width="400" cellspacing="2" cellpadding="2" align="center">
<?php

$perpage = 5;

if(isset($_GET["page"])){
$page = intval($_GET["page"]);
}
else {
$page = 1;
}
$calc = $perpage * $page;
$start = $calc - $perpage;
$result = mysqli_query($conn, "select * from countries Limit $start, $perpage");

$rows = mysqli_num_rows($result);

if($rows){
$i = 0;
while($post = mysqli_fetch_assoc($result)) {
?>
<tbody>
<tr style="background-color: #cccccc;">

<td style="font-weight: bold;font-family: arial;"><?php echo $post["ccode"]; ?></td>

</tr>

<tr>

<td style="font-family: arial;padding-left: 20px;"><?php echo $post["country"]; ?></td>

</tr>
<?php
}
}
?>

</tbody>
</table>


<table width="400" cellspacing="2" cellpadding="2" align="center">
<tbody>
<tr>
<td align="center">

<?php

if(isset($page))

{

$result = mysqli_query($conn,"select Count(*) As Total from countries");

$rows = mysqli_num_rows($result);

if($rows)

{

$rs = mysqli_fetch_assoc($result);

$total = $rs["Total"];

}

$totalPages = ceil($total / $perpage);

if($page <=1 ){

echo "<span id='page_links' style='font-weight: bold;'>Prev</span>";

}

else

{

$j = $page - 1;

echo "<span><a id='page_a_link' href='pagination.php?page=$j'>< Prev</a></span>";

}

for($i=1; $i <= $totalPages; $i++)

{

if($i<>$page)

{

echo "<span><a id='page_a_link' href='pagination.php?page=$i'> -$i- </a></span>";

}

else

{

echo "<span id='page_links' style='font-weight: bold;'>$i</span>";

}

}

if($page == $totalPages )

{

echo "<span id='page_links' style='font-weight: bold;'>Next ></span>";

}

else

{

$j = $page + 1;

echo "<span><a id='page_a_link' href='pagination.php?page=$j'>Next</a></span>";

}

}

?></td>
<td></td>
</tr>
</tbody>
</table>

</body>
</html>

Wednesday, November 15, 2017

form validation on submit button

<html lang="en">
<head>
  <title>Jagran Form</title>
 
 
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"></link>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script>
   function ValidateMob(inputText,adhar_no) 
{
    var inputText = inputText.value;
    var adhar_no = adhar_no.value;
   //alert(inputText);
   //alert(adhar_no);
//var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; 
if(isNaN(parseInt(inputText))) 

document.form1.mobile_no.focus(); 
alert("You have entered an Wrong Mobile Number!"); 
return false; 

else if(!(inputText.length == 10))

alert("You have entered an Wrong Mobile Number!"); 
document.form1.mobile_no.focus();
//alert("length");
return false; 


else if(isNaN(parseInt(adhar_no))) 

document.form1.adhar_no.focus(); 
alert("You have entered an Wrong Aadhar Number!"); 
return false; 

else if(!(adhar_no.length == 12))

alert("You have entered an Wrong Aadhar Number!"); 
document.form1.adhar_no.focus();
//alert("length");
return false; 

else {
   return true;
}
}

</script>
</head>
<body>

    <div class="row" style="background-color: #e8ecf2; padding: 10px 10px 10px 10px;">
    <div class="col-sm-1">
     
    </div>
<div class="col-sm-4">
      <img height="57px" src="image/jamajamoffer.png" style="align: left;" width="100px" />
      <h2 style="border-left: 1px solid #000; display: inline-block; font-size: 24px; font-weight: normal; margin: 22px 0 0 10px; padding: 7px 20px 0; vertical-align: bottom;">
 Insurance Data Details </h2>
</div>
<div class="col-sm-2">
       <a href="https://www.blogger.com/logout.php" style="border-left: 1px solid #000; display: inline-block; font-size: 18px; font-weight: normal; margin: 22px 0 0 10px; padding: 7px 20px 0; vertical-align: bottom;">LOGOUT</a>
    </div>
</div>
<div class="container">
 
  <div class="row">
    <div class="col-sm-3">
     
    </div>
<div class="col-sm-6" style="border-left: 1px solid #cedbef; padding-bottom: 20px; padding-top: 20px;">
         
         
            <div class="alert alert-success">
  <strong>Success!</strong> Data successful saved.
</div>
<div class="alert alert-danger">
                <strong>Error!</strong> Duplicate Data.
            </div>
<form action="saveindb.php" method="POST" name="form1" onsubmit="return ValidateMob(document.form1.mobile_no,document.form1.adhar_no) ">
  <div class="form-group">
    <label for="email">सब्सक्राइबर का नाम -</label>
    <input class="form-control" name="sub_name" required="required" type="text" />
  </div>
<div class="form-group">
    <label for="email">सब्सक्राइबर का पता -</label>
    <input class="form-control" name="sub_address" required="required" type="text" />
  </div>
<div class="form-group">
    <label for="email">शहर का नाम - </label>
    <input class="form-control" name="city" required="required" type="text" />
  </div>
<div class="form-group">
    <label for="email">जिले का नाम - </label>
    <input class="form-control" name="district" required="required" type="text" />
  </div>
<div class="form-group">
    <label for="email">जन्म तिथि -</label>
    <input class="form-control" name="dob" required="required" type="date" />
  </div>
<div class="form-group">
    <label for="email">व्यवसाय / कारोबार - </label>
    <input class="form-control" name="business" required="required" type="text" />
  </div>
<div class="form-group">
    <label for="email">नॉमिनी का नाम -</label>
    <input class="form-control" name="nomini_name" required="required" type="text" />
  </div>
<div class="form-group">
        <label for="email">आधार क्रमांक संख्या - </label>
        <input class="form-control" name="adhar_no" required="required" type="text" />
    </div>
<div class="form-group">
        <label for="email">मोबाइल नंबर -  </label>
        <input class="form-control" mobile="" name="mobile_no" type="text" value="&lt;?php echo $_SESSION[" />" readonly&gt;
        <input divn="" name="divn" type="hidden" value="&lt;?php echo $_SESSION[" />" &gt;
    </div>
<div class="checkbox">
         <label><input required="required" type="checkbox" value="" />I declare that the above answers are true to the best of my knowledge and belief,
  that I have desclosed all particulars affecting assessment of the risk. I agree that this is the basic of the contract between me and this Company.
  </label>
</div>
<input name="submit" type="submit" value="Submit" />
</form>
</div>
<div class="col-sm-3">
   
    </div>
</div>
</div>
<div class="row" style="background-color: #999999; border: 1px solid #99999; padding: 10px 10px 10px 10px;">
    <div class="col-sm-1">
     
    </div>
<div class="col-sm-4">
        <img height="30px" src="image/jagran-logo.png" style="align: left;" width="50px" /> &nbsp; Copyright Jagran Prakashan Limited. All Rights Reserved
    </div>
</div>
</body>
</html>

Tuesday, November 14, 2017

(SOLVED) Converting utf8 to html-entities worked . php header excel and utf-8

<?php

header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename="sample.xls"');
echo "
    <html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">
    <html>
        <head><meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\" /></head>
        <body>
";

echo  "

<table
>
<thead>
<tr>
<th>Subs Name</th>
<th>Mobile No</th>
<th>Address</th>
<th>City</th>
<th>District</th>
<th>DOB</th>
<th>Occupation</th>
<th>Nominee</th>
<th>Adhaar No</th>
</tr>
</thead>
<tbody>
<tr>
<td >सत्येन्द्र यादव </td>
<td>8299514347</td>
<td>रावतपुर</td>
<td>कानपूर </td>
<td>कानपूर </td>
<td>01-SEP-17</td>
<td>टेस्ट </td>
<td>प्रदीप सर </td>
<td>123456789123</td>
</tr>
<tr>
<td >राम दास</td>
<td>9628177885</td>
<td>राम नगर</td>
<td>कानपुर</td>
<td>कानपुर</td>
<td>05-OCT-17</td>
<td>स्टूडेंट</td>
<td>सीता</td>
<td>987645682154</td>
</tr>
</tbody>
</table>
    ";


echo "</body></html>";

?>

Thursday, August 31, 2017

codeigniter query in array

I have tried a few different approaches to this problem with no solutions so far. I am receiving error message:



down voteaccepted
The array you try to pass is a multi dimensional array. Instead try this:
$ids = array();
foreach ($query->result_array() as $id)
    {
        $ids[] = $id['id'];
    }

$this->db->where_in('id', $ids);
codeigniter function Example for where in array query:-
function getMultiCast($religion_id) {
  $this->db->where_in("religion_id", $religion_id);
  $query = $this->db->get("castlist");
  return $query->result();
 }