Skip to content

Instantly share code, notes, and snippets.

@DilzGithub
DilzGithub / DROPDOWN list depend on another dropdown__Controller.php
Created January 20, 2018 05:08
Pass selected data via dropdown into db and retrive the related data into another dropdown list.. the dropdown list depend on another dropdown list. in this case, need to use Ajax for pass the selected id value into the php server side.
<?php
public function get_sub_researchs()
{
$research_group_id = $this->input->post('research_group_id'); // this input come from ajax post.
var_dump($research_group_id);
$sub_researchs = $this->profile_model->get_sub_research($research_group_id);
if(count($sub_researchs) > 0)
{
@DilzGithub
DilzGithub / WHERE query when join tables ___ Module.php
Created January 19, 2018 04:49
WHERE query when using it wiith join queries.
<?php
public function get_profile_data()
{
$this->db->Select('*');
$this->db->join('faculties','faculties.faculty_id = profiles.faculty_id','left');
$this->db->join('departments','departments.dept_id = profiles.dept_id','left');
$this->db->join('users','users.user_id = profiles.user_id','left');
// when using where in this case should mention the table name also. because there are some join queries.
// so module will not able to get the correct where field if not mention the table name.
@DilzGithub
DilzGithub / GET DATA into View with dropdown box__ Contoller.php
Created January 16, 2018 10:55
Get saved data via dropdown box, into the edit view with JOIN query
<?php
public function edit_profile()
{
$pro_id = $this->uri->segment(3);
$profile_data = $this->profile_model->profile_data($pro_id);
$pro_data['profileEdit'] = $profile_data;
$this->load->view('profile/edit_profile',$pro_data);
}
@DilzGithub
DilzGithub / JS File Size Checking___ Javascript.js
Last active January 19, 2018 04:52
check file size and file extension prior to upload
<script type="text/javascript">
var uploadField = document.getElementById("userfile");
uploadField.onchange = function() {
if(this.files[0].size > 1048576){
alert("Unable to proceed upload, File is larger than 1mb.");
this.value = "";
};
};
@DilzGithub
DilzGithub / File UPLOAD__Controller.php
Created January 15, 2018 09:10
Upload Image file and save the file name in database
<?php
public function image_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 1000;
$config['max_width'] = 500;
$config['max_height'] = 500;
@DilzGithub
DilzGithub / CURRENT DATE . js
Created January 13, 2018 03:12
Get current date into an input box.
<script type="text/javascript">
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd;
}
@DilzGithub
DilzGithub / Insert autoincrement id in another table__ Controller.php
Last active January 19, 2018 04:53
Insert autoincrement id in another table as a foreign key.
<?php
if($this->form_validation->run())
{
$user_id = $this->user_model->add_user($data);
// assign the autoincremented user id into this $user-id
if($role == "Editor"){ //this code will run if the user select 'Editort' as the role.
// then this will insert the below information in another table called 'profile'.
$data = array(
'user_id' => $user_id, // user id which retrived from users table autoincremented id frield.