check validation between to dates and time - php

I have this if statement
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$(document).on('submit', '#rentform', function () {
var data = $(this).serialize()
$.ajax({
type: 'POST',
url: 'newrent.php',
data: data,
success:(
function (data){$(".result").html(data)}
)
});
return false;
});
} )
$(document).ready(function () {
$('#rent').change(function(){
var x =($('#rent option:selected').data('sireal'))
$('#itemsn').val(x);
});
} )
</script>
<form method="post" id="rentform" action="" novalidate="novalidate">
<label for="item">REnter Name</label>
<select name="rnt_name" id="name_rent">
<option selected disabled>SELECT Renter Name</option>
<?php foreach ($nameq as $res) : ?>
<option value="<?= $res['user_name']?>"><?= $res['user_name'] ?></option>
<?php endforeach; ?>
</select>
<br/>
<br/>
<label for="item">Cameras</label>
<select name="item" id="rent">
<option selected disabled>SELECT ITEM</option>
<?php foreach ($rentq as $row) : ?>
<option value="<?= $row['item_brand']?>" data-sireal="<?= $row['s_n'] ?>"><?= $row['item_brand'] ?></option>
<?php endforeach; ?>
</select><br/>
<br/>
<input type="hidden" name="sn" id="itemsn" value="">
<label name="from_date">RENT FROM</label>
<input type="date" name="from_date"><br/>
<label name="from_hour">RENT FROM Hour</label>
<input type="time" name="from_hour"><br/>
<label name="to_date">RENT TO</label>
<input type="date" name="to_date"><br/>
<label name="to_hour">RENT FROM Hour</label>
<input type="time" name="to_hour"><br/>
<input type="submit" name="submit" value="Send Rent">
</form>
<div class="result">
</div>
if($_POST){
$name = $_POST['rnt_name'];
$item = $_POST['item'];
$fdate = $_POST['from_date'];
$fhour = $_POST['from_hour'];
$tdate = $_POST['to_date'];
$thour = $_POST['to_hour'];
$sn = $_POST['sn'];
$csheck = "SELECT * FROM rent";
$ckq = mysqli_query($link,$csheck);
foreach ($ckq as $res) {}
$count = "SELECT item_brand = '$item',s_n = '$sn',COUNT(*)
FROM item
WHERE status = 1 AND item_brand = '$item' AND s_n = '$sn'";
$cnt = mysqli_query($link,$count);
foreach ($cnt as $itm);
$itmq = "SELECT rent_item = '$item',COUNT(*)
FROM rent ";
$itemres = mysqli_query($link,$itmq);
foreach ($itemres as $missitm){};
if(($fdate >= $res['rent_from_d'] && $res['rent_to_d'] >= $tdate && $missitm['COUNT(*)'] >= $itm['COUNT(*)'] ) || ($fdate > $res['rent_from_d'] && $res['rent_to_d'] > $tdate && $fdate > $res['rent_from_d'] || $fdate <= $res['rent_to_d'] && $fhour <= $res['rent_to_t'] && $missitm['COUNT(*)'] >= $itm['COUNT(*)'] ) ) {
echo 'no good Item Rented To '.$res['renter'] ;
}else{
$newrent = "INSERT INTO rent (renter,rent_item,rent_from_d,rent_from_t,rent_to_d,rent_to_t)
VALUES ('$name','$item','$fdate','$fhour','$tdate','$thour')";
mysqli_query($link,$newrent);
echo 'pass';
}
this is what I get in my database after form submit
rent_id renter rent_item sn rent_from_d rent_from_t rent_to_d rent_to_t
115 dror x70 1234 2018-11-29 10:00 2018-11-29 14:00
What I am trying to do is create a rent system. My problem is how to validate if items are selected between two dates and time. Every time new rent is created, the status of the specific item that has been chosen set to 0, so that the system will no longer available.
Thanks in advance.

Related

how to search input keyword from user database resume in codeigniter

I have one text box name is Skills , if admin enter skill name we will get user data based on the user skills in database field . it will working fine . i can display all users data based on the skill set .
My requirement is if admin search any skill that skill is mentioned user in Resume also .i need based on the resume also display data in codeigniter. can you any one please help out this problem. Please find below QUERY in model.
SELECT js_simple.js_id,js_simple.firstname,js_skills_achievements.skill,js_ResumeDetails.fileResume,js_ResumeDetails.profileImage FROM js_simple LEFT JOIN js_skills_achievements ON js_skills_achievements.js_id = js_simple.js_id WHERE js_skills_achievements.skill = '".trim($skill)."'
This is working for me , my requirement is user having resume . with in the resume suppose user mention skills is PHP,JAVA,SQL. if admin search any skill RESUME also i need search . What is QUERY for this in codeigniter model .
view.php
<form id="advance_search" action="" method="post">
<div class="col-md-8" style="border: 2px solid lightgray;padding: 0px 0px 9px 0px;">
<div class="advanced_serach_bg" style="background: #4a90cc;">
<div class="col-md-8">
<h4 style="color:#fff;"> Quick Search </h4>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label style="color:#323232;" for="pincode">Any keyword</label>
<input style="color:#535353; background:#f1f1f1;height: 35px;" id="keywords" class="form-control" name="keywords" type="text">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label style="color:#323232;" for="pincode">Location</label>
<input style="color:#535353; background:#f1f1f1;" id="location" class="form-control" name="location" placeholder="Enter Location" type="text">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label style="color:#323232;" for="activein">Active in:</label>
<select style="background: #4a90cc;color:#fff;margin-top:2px;" name="active_records" id="active_records" class="form-control" >
<option value='3 day'> 3 days</option>
<option value='1 week'> 1 week</option>
<option value='30 day'> 30 days</option>
<option value='2 MONTH'> 2 months</option>
<option value='3 MONTH'> 3 months</option>
<option value='4 MONTH'> 4 months</option>
<option value='5 MONTH'> 5 months</option>
<option value='6 MONTH'> 6 months</option>
<option value='7 MONTH'> 7 months</option>
<option value='8 MONTH'> 8 months</option>
<option value='9 MONTH'>9 months</option>
<option value='10 MONTH'> 10 months</option>
<option value='11 MONTH'> 11 months</option>
<option value='12 MONTH'> 12 months</option>
<option value='10 Year'> 1 + Year</option>
</select>
</div>
</div>
<div class="clearfix"></div>
<br>
<div class="form-group">
<div class="col-md-offset-5 col-sm-4">
<input type="submit" value="Search" class="btn btn-normal subbtn">
</div>
</div>
</div>
</form>
javascript
<script>
$(function(){
$('form#advance_search').submit(function(e) {
e.preventDefault();
var formData = $('form#advance_search').serializeArray();
//var keywords = $('#keywords').tagEditor('getTags')[0].tags;
//console.log(keywords);
$.ajax({
url:"<?php echo base_url();?>newrecruiter_control/candidate_advance_search",
type:"post",
data:formData,
success:function(data) {
window.location.href="<?php echo base_url();?>newrecruiter_control/search_candidate";
}
});
});
});</script>
newrecruiter_control.php
public function candidate_advance_search() {
$this->recruiter_model->delete_candidate_search();
$data['job_seeker'] = $this->recruiter_model->advance_candidate_search();
}
recruiter_model.php
<?php
public function advance_candidate_search() {
$data = array(
'active_records' => $this->input->post('active_records')?$this->input->post('active_records'):'3 day',
'search_keyword' => $this->input->post('keywords')?$this->input->post('keywords'):'',
'semantic_search' => $this->input->post('search_mode')?$this->input->post('search_mode'):'ON',
'search_in_resume' => 'NO' //$this->input->post('search_resume')
);
$sql_query = $this->db->select('*')
->from('recruiter_recent_search_results')
->where('recruiter_id',$this->session->userdata('recruiter_id'))
->get();
if($sql_query->num_rows() >= 5 ){
$this->db->delete('recruiter_recent_search_results',array('recruiter_id' => $this->session->userdata('recruiter_id')));
}else{
$exp = $data['min_experience'];
$this->db->insert('recruiter_recent_search_results',array('recruiter_id' => $this->session->userdata('recruiter_id'),'skills' => strtoupper($data['search_keyword']), 'location' => ucfirst($data['location']),'experience' => $exp));
}
if($data['search_in_resume'] == 'YES') {
/*
if($data['semantic_search'] == 'OFF') {
$response_array = $this->getAdvanceSearchResultInResume($data);
}else{
$response_array = $this->getAllSearchResultInResume($data);
}*/
}else{
if($data['semantic_search'] == 'OFF') {
$response_array = $this->getAdvanceSearchResult($data);
}else{
$response_array = $this->getAllSearchResult($data);
}
}
}
public function getAllSearchResult($data) {
$search_query = "SELECT js_simple.js_id,js_simple.firstname,js_simple.lastname,js_simple.added_date,js_skills_achievements.skill1,js_ResumeDetails.percentage,js_ResumeDetails.fileResume,js_ResumeDetails.profileImage,js_ResumeDetails.profile_type,js_ResumeDetails.about_self FROM js_simple LEFT JOIN js_skills_achievements ON js_skills_achievements.js_id = js_simple.js_id LEFT JOIN js_ResumeDetails ON js_ResumeDetails.js_id = js_simple.js_id WHERE js_simple.added_date >= DATE_SUB(NOW(),INTERVAL ".$data['active_records']." ) ";
if($data['search_keyword'] != NULL) {
$search_key = explode(',',$data['search_keyword']);
if(count($search_key) == 1) {
$search_query .= " AND (js_skills_achievements.skill1 = '".trim($search_key[0])."' OR js_ResumeDetails.about_self LIKE '%".trim($search_key[0])."%')";
$str = $this->db->last_query($search_query);
echo $str;
}
}
$search_query .= " GROUP BY js_simple.js_id ORDER BY js_simple.added_date DESC LIMIT ".$data['sort_by'];
$response = $this->db->query($search_query);
// return $this->db->last_query();
return $response->result_array();
}
public function getAdvanceSearchResult($data) {
$this->db->select('*');
$this->db->from('js_simple,js_skills_achievements,js_ResumeDetails');
$this->db->join('js_skills_achievements','js_skills_achievements.js_id = js_simple.js_id','left');
$this->db->join('js_ResumeDetails','js_ResumeDetails.js_id = js_simple.js_id','left');
$this->db->where("js_simple.added_date >= DATE_SUB(NOW(),INTERVAL ".$data['active_records']." )",NULL,FALSE);
if($data['search_keyword'] != NULL) {
$search_key = explode(',',$data['search_keyword']);
if(count($search_key) == 1) {
$this->db->where('js_skills_achievements.skill1',$search_key[0]);
}
}
$this->db->group_by('js_simple.js_id');
$this->db->order_by('js_simple.added_date','desc');
if($data['sort_by'] != NULL) {
$this->db->limit($data['sort_by']);
}
$search_response = $this->db->get();
return $search_response->result_array();
}
public function getAllSearchResultInResume($data) {
$jobseekers = '';
$get_js_details = $this->getAllSearchResult($data);
foreach($get_js_details as $key => $jobseeker) {
if($jobseekers == NULL) {
$jobseekers .= $jobseeker['js_id'];
}else{
$jobseekers .= ','.$jobseeker['js_id'];
}
}
}
?>

php dropdown show selected but one value by defaut

i'm using php for stored procedure on sql server. My problems is that i would like to show one value by defaut on the dropdown, but when someone select something else and the page refresh, it must show the what that person choose, not the default one. Here what i had done until now :
<form method="post">
<label for="from"><b>De:</b></label>
<input data-date-format='yy-mm-dd' type="text" id="from" name="from" size="6" value="<?php if(isset($_POST['from'])){ echo $_POST['from']; } ?>";/>
<label for="to"><b>A:</b></label>
<input data-date-format='yyyy-mm-dd' type="text" id="to" name="to" size="6" value="<?php if(isset($_POST['to'])){ echo $_POST['to']; } ?>";/>
<label for="group"><b>Groupe:</b></label>
<select type= "text" name="group" id="group" value="";>
<option><?php if(isset($_POST['group'])){ echo $_POST['group']; } ?></option>
<?php
$sql = " Get_List_ReportStation";
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
{
?>
<option selected value="RAL"><?php echo ($row['F1000'] . " " . $row['F1018']); ?></option>
<?php
}
?>
</select>
<input type="submit" value="Valider" name="submit">
</form>
<?php
if(isset($_POST["submit"])) {
$from = $_POST["from"];
$to = $_POST["to"];
$group = $_POST["group"];
}
?>
Any ideas to help me? Thank you!
<select class="group">
<option value="test1">test1</option>
<option value="test2">test2</option>
<option value="test3">test3</option>
<option value="test4">test4</option>
</select>
Add Javascript to store the users last value into localstorage.
var select = document.querySelector(".group");
var selectOption = select.options[select.selectedIndex];
var lastSelected = localStorage.getItem('select');
if(lastSelected) {
select.value = lastSelected;
}
// sets up a onselected
select.onchange = function () {
lastSelected = select.options[select.selectedIndex].value;
console.log(lastSelected);
localStorage.setItem('select', lastSelected);
}
Source: How to use LocalStorage on last HTML select value
For your given code try this
<form method="post">
<label for="from"><b>De:</b></label>
<input data-date-format='yy-mm-dd' type="text" id="from" name="from" size="6" value="<?php if(isset($_POST['from'])){ echo $_POST['from']; } ?>";/>
<label for="to"><b>A:</b></label>
<input data-date-format='yyyy-mm-dd' type="text" id="to" name="to" size="6" value="<?php if(isset($_POST['to'])){ echo $_POST['to']; } ?>";/>
<label for="group"><b>Groupe:</b></label>
<select type= "text" name="group" id="group">
<option><?php if(isset($_POST['group'])){ echo $_POST['group']; } ?></option>
<?php
$sql = " Get_List_ReportStation";
$stmt = sqlsrv_query($conn, $sql);
if( $stmt === false) {
die( print_r( sqlsrv_errors(), true) );}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
{
?>
<option value="<?php echo ($row['F1000']."_".$row['F1018']); ?>"><?php echo ($row['F1000'] . " " . $row['F1018']); ?></option>
<?php
}
?>
</select>
<input type="submit" value="Valider" name="submit">
</form>
<script>
var select = document.querySelector(".group");
var selectOption = select.options[select.selectedIndex];
var lastSelected = localStorage.getItem('select');
if(lastSelected) {
select.value = lastSelected;
} else {
select.value = 'RAL'; // new code
}
// sets up a onselected
select.onchange = function () {
lastSelected = select.options[select.selectedIndex].value;
console.log(lastSelected);
localStorage.setItem('select', lastSelected);
}
</script>
<?php
if(isset($_POST["submit"])) {
$from = $_POST["from"];
$to = $_POST["to"];
$group = $_POST["group"];
}
?>

Validation for multiselect using PHP

I have a multiple select on my code, what I need to do is to have a validation when the user click the submit button without selecting any of the given list.
Here's the sample code:
index.php
<?php
IF(isset($_POST['Rtype'])){
$RetrieveType = $_POST['Rtype'];
IF($RetrieveType == 'date_range'){
$start_date = new DateTime($_POST['start_date']);
$sd = date_format($start_date,'Y-m-d');
$p_week=array();
$m_month=01;
$end_date = new DateTime($_POST['end_date']);
$end_date-> add(new DateInterval('P1D'));
$ed =date_format($end_date,'Y-m-d');
}
ELSEIF($RetrieveType == 'weekly'){
$p_week = $_POST['week'];
$m_week = implode(',',$p_week);
$m_month =$_POST['month_m'];
$m_year =$_POST['year_m'];
$p_lob = $_POST['lob'];
$sc_lob=implode(',',$p_lob);
} ELSE
{
$RetrieveType = 'date_range';
$sd = date('Y-m-01');
$start_date = date('Y-m-01');
$ed = date('Y-m-d');
$end_date = date('Y-m-d');
$m_month=date ('m');
$p_week=array();
$m_year= date ('Y');
$sc_lob='';
}
?>
<html>
<head>
<head>
<body>
<form action="index.php" method="POST" class="form-inline">
<label for="sel1">Week:</label>
<select data-placeholder="<?php echo (isset($_POST['week']) ? "Week/s Currently Selected: ".implode(",",$_POST['week']) : "Select Week"); ?>"
class="chosen-select" multiple tabindex="4" style="width:350px;" name= "week[]">
<option value="1" id="empty">Week 1</option>
<option value="2" id="empty">Week 2</option>
<option value="3" id="empty">Week 3</option>
<option value="4" id="empty">Week 4</option>
<option value="5" id="empty">Week 5</option>
</select>
<label for="sel1">LOB:</label>
<select data-placeholder="<?php echo (isset($_POST['lob']) ? "LOB/s Currently Selected: ".implode(",",$_POST['lob']) : "Select LOB"); ?>"
class="chosen-select" multiple tabindex="4" style="width:350px;" name= "lob[]">
<?php
$lob = array();
$q = "SELECT distinct LOB from roster where EmployStatus='active' and SDLead <> '' group by LOB";
$params = array();
$query = sqlsrv_query($conn, $q);
while($rowsss= sqlsrv_fetch_array($query)) {
$lob = $rowsss['LOB'];
echo "<option value='".$lob."'>".$lob."</option>";
}
for ($i = 0; $i <= count($lob) - 1; $i++) {
IF($sc_lob == $lob[$i])
{$isSelected = 'selected';}
elseif(1==1)
{$isSelected='';}
echo "<option ".$isSelected." value='".$lob[$i]."'>".$lob[$i]."</option>"; }
?>
<input type="hidden" name="Rtype" value="weekly">
<input class="btn btn-primary" type="submit" />
</form>
What I wanted to achieve is when the user clicked the submit button without selecting any on the "Week" list or "LOB" list, there would be an error message that says "This field is required, select at least one.". Actually I already did this before, when I'm just using a checkbox. I placed the code below after the label tag:
sample code:
<?php
if(isset($_GET['err']))
{
$err = $_GET['err'];
if($err == 1)
{
echo "<span class='text-danger'>* This field is required, select at least one.</span>";
}
else
{
echo "";
}
}
else
{
echo "";
}
?>
Try this
if(isset($_POST['submit']){
errors = 0;
if($_POST['nameOfSelect'] == ""){
errors++;
}
if(errors == 0){
return true;
}else{
return false;
}

AJAX posted variable behaving unexpectedly

So I have an AJAX process that submits a variable from a select option in a HTML form, and then builds another select menu from that. Essentially what is supposed to happen is that, for example, if the user selects the month of Feburary, the variable sent to the PHP script will be '02' and then the new dropdown box will have 29 options. The problem is that, despite my script telling me that 02 has been sent, the days are all out of whack. The days don't seem to correlate to the months, however despite the days being wrong, they're always consistently wrong. For example, while Feburary doesn't print 29 days, it will always consistently print the '30' days option, no matter whether it's 30, or 8000.
Here is my javascript file:
$(document).ready(function() { //Makes sure page is loaded.
/* === LINKS ===
Controls the links (site behaviour) via JQuery (as
defined by the Assignment CRA).
*/
$('#home').html('Home');
$('#signup').html('Sign Up');
$('#activities').html('Upcoming Activities');
$('#feedback').html('Student Feedback');
$('#contact').html('Contact');
/* === STAFF INFORMATION TOGGLE ===
Displays or hides information about
staff members on click.
*/
/*
$('#spongeimage').click(function() {
$("#spongeinfo").slideToggle("slow");
});*/
$(".staff").click(function() {
//alert("ALERT");
$(".staffinfo", this).slideToggle("slow");
});
$('#year').change(function() {
$("#month").slideToggle("slow");
});
$('#month').change(function() {
var month_var = $("#month").val();
var dataString = 'name1='+ month_var;
//Start
$.ajax({
type: "POST",
url: "./javascript/month_post.php",
data: dataString,
dataType: "text",
success: function(data) {
//alert(dataString);
$("#day").html(data);
$("#okay").html(dataString);
}
});
//End
$("#day").slideToggle("slow");
});
/* === 'FIRST NAME' FORM FOCUS
Focuses the cursor on the 'first name'
field when the Student Feedback page
is loaded.
*/
$('input[name="firstname"]').focus();
/* === HOVER EFFECTS ===
The effects that occur after hovering over
an item on the link bar (1.0) and one of
the two buttons on the Student Feedback
page (1.1).
*/
//(1.0)
$("li a").hover(function(){
$(this).css({"color": "#000000", "background-color": "#5590ff"});
}, function(){
$(this).css({"color": "#333", "background-color": "#FFFFFF"});
});
//(1.1)
$("formbutton").hover(function(){
$(this).css({"color": "#000000", "background-color": "#5590ff"});
}, function(){
$(this).css({"color": "#333", "background-color": "#FFFFFF"});
});
});
Here is my PHP file:
<?php
echo $name;
if(isset($_POST["name1"]))
{
$name = $_POST["name1"];
//echo $name;
// Here, you can also perform some database query operations with above values.
//echo "Welcome ". $name ."!"; // Success Message
$counter = 1;
//echo "<select name='gday'>";
if($name == 02)
{
$monthdays = 29;
}
if($name == 06 || $name == 09 || $name == 04 || $name == 11)
{
$monthdays = 30;
}
else
{
$monthdays = 31;
}
while ($counter <= $monthdays)
{
echo "<option value='hi'>".$counter."</option>";
$counter++;
}
//echo "</select>";
}
?>
And here is my HTML file:
<!DOCTYPE html>
<html>
<head>
<title>KIT411 - Homepage</title>
<link rel="stylesheet" href="./CSS/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="./javascript/script.js"></script>
</head>
<body>
<!-- TITLES -->
<div class="titles">
‌ <!-- Blank character, to ensure the titles div extends to the top of the page. -->
<h1 class="title">KIT411</h1> <!-- Unit name. -->
<h2 class="subtitle">Sign Up</h2> <!-- Page name. -->
</div>
<div class="right">
<?php
include('login.php');
?>
</div>
<!-- PAGE LINKS
Links are controlled by JQuery, which is why
there are no <a></a> tags. -->
<?php
include('PHP/linkbar.php');
?>
<div class="center">
<div class="inline">
<?php
include('./db-connection/register.php');
?>
<div id="okay">TEST </div>
<form method="post" action="">
Username:<br>
<input type="text" name="usr" value="<?php echo $user; ?>"><br>
Password:<br>
<input type="password" name="pass" value="<?php echo $password; ?>"><br>
Retype Password:<br>
<input type="password" name="pass2" value="<?php echo $passwordTwo; ?>"><br>
Name:<br>
<input type="text" name="name" value="<?php echo $name; ?>"><br>
DOB:<br>
<select id="day" name="dobDay">
<?php
$counter = 1;
while($counter <= 31)
{
?>
<option value="<?php echo $counter; ?>"><?php echo $counter; ?></option>
<?php
$counter++;
}
?>
</select>
<select id="month" name="dobMonth">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="year" name="dobYear">
<?php
$counter = 1100;
while($counter <= 2016)
{
?>
<option class="yearClass" value="<?php echo $counter; ?>"><?php echo $counter; ?></option>
<?php
$counter++;
}
?>
</select>
<br>
Email:<br>
<input type="text" name="email" value="<?php echo $email; ?>"><br>
<input type="submit" name="submit" value="Sign Up">
</form>
</div>
</div>
<?php
include('PHP/footer.php');
?>
</body>
</html>
Any help would be greatly appreciated, and sorry if there's any swearwords in my code. Sometimes I do it for a bit of fun while testing and forget to remove them. Anyway, any help is progress.
The problem is in the PHP code, when you try to set up the number of days. You have one if and one if ... else, but doesn't behave as you expect.
You have first this if
if($name == 02)
{
$monthdays = 29;
}
And after this one:
if($name == 06 || $name == 09 || $name == 04 || $name == 11)
{
$monthdays = 30;
}
else
{
$monthdays = 31;
}
This last one will set up the number of days to 30 or 31, because it only have two choices. Here you could use an elseif control structure. http://php.net/manual/en/control-structures.elseif.php
if ($name == 02)
{
$monthdays = 29;
}
else if ($name == 06 || $name == 09 || $name == 04 || $name == 11)
{
$monthdays = 30;
}
else
{
$monthdays = 31;
}

Codeigniter : Jquery fill the textbox based on combobox

I am Nubie in JQuery especially in ajax..
I have read articles about dropdown combobox (read from database) then fills other textbox (read from database based on combobox data) but I have confused
I Need Jquery / Ajax / something to show it
can someone solve my problem and explain to me..
Controller
public function tambah()
{
$cek = $this->session->userdata('logged_in');
if(empty($cek))
{
header('location:'.base_url().'app_admin');
}
else
{
$d['nama_madrasah'] = "";
$d['nsm'] = "";
$d['provinsi'] = "";
$d['alamat'] = "";
$d['kecamatan'] = "";
$d['kab_kota'] = "";
$d['jenis_bantuan'] = "";
$d['jenjang'] = "";
$d['th_ang'] = "";
$d['sumber_dana'] = "";
$d['tahap_pencairan'] = "";
$d['st'] = "tambah";
$d['dt_nsm'] = $this->app_model->ShowNSMMaster();
$this->load->view("app_admin/madrasah/input",$d);
}
}
My View
<select data-placeholder="Cari NSM..." class="chzn-select" style="width:260px;" tabindex="2" name="nsm" id="dt_nsm" >
<?php
if($st=='edit')
{
?>
<option value="<?php echo '$nsm'; ?>" selected="selected"><?php echo '$nsm'; ?></option>
<?php
}
else
{
?>
<option value="" selected="selected">- Pilih -</option>
<?php
foreach($dt_nsm->result_array() as $dp1)
{
?>
<option value="<?php echo $dp1['nsm']; ?>"><?php echo $dp1['nsm']; ?> | <?php echo $dp1['nama_madrasah']; ?></option>
<?php
}
}
?>
</select>
</span></div>
<label class="control-label" for="nama_madrasah">Nama Madrasah </label>
<div class="controls">
<input type="text" class="span" name="nama_madrasah" id="nama_madrasahx" value="<?php echo $nama_madrasah; ?>" placeholder="">
</div>
<label class="control-label" for="alamat">Alamat</label>
<div class="controls">
<input type="text" class="span" name="alamat" id="alamatx" value="<?php echo $alamat; ?>" placeholder="">
</div>
JS
<script type="text/javascript">
$('#dt_nsm').on('change', function(){
dt_nsm = $('#dt_nsm option:selected').val(); // the dropdown item selected value
$.ajax({
type :'POST',
dataType:'json',
data : { dt_nsm : dt_nsm },
url : 'getresult.php',
success : function(result){
$('#nama_madrasahx).val(result['nama_madrasahx']);
$('#kecamatanx).val(result['kecamatanx']);
}
});});
</script>
getresult.php
<?php
require_once ('../config/db.config.php');
$dt_nsm = $_POST['dt_nsm'];
$query = "SELECT * FROM bantuan WHERE nsm = '$nsm' ";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo json_encode($row);
?>
Thanks For your time. Need Advice !
change
foreach($dt_nsm->result_array() as $dp1)
to
foreach($dt_nsm->result_array() as $key=>$dp1)

Categories