Just Sharing Knowledge on Robotics, Electronics and Programming

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Friday, August 24, 2018

[SOLUTION] Select Database The N numbers Last or First Rows in Codeigniter


 
If you want to select the N last rows or N first rows, in codeigniter you can use the following script


$n = 100;
$this->db->limit(n); 
$this->db->order_by("id", "desc"); // N last rows 
$query = $this->db->get('my_table');
$myRow = $query->row();
 
 
$n = 100; 
$this->db->limit(n); 
$this->db->order_by("id", "asc"); // N first rows 
$query = $this->db->get('my_table');
$myRow = $query->row(); 
 

Wednesday, June 13, 2018

[SOLVED] How to move Application Folder to the Basepath (root) in Codeigniter



Codeigniter Application folder is where our job begin, the default structure of codeigniter is

basepath/aplication
basepath/system

now you want to move your application content to the site, you can use the following way

in index.php :

on line 117 change value to empty then

$application_folder = '';

and in line 239 change from

if (is_dir($application_folder))

to 

if ($application_folder=='')

Done.

Wednesday, June 6, 2018

[SOLVED] Codeigniter DB Error "The mysql extension is deprecated ..."


Codeigniter is popular PHP framework that helps you in php programming, if you using Apache server with PHP 5.5 above, you will see the following error when you using database mysql :
mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
To solve this issue you have to add a line of the following script 
 
 error_reporting(error_reporting() & ~E_DEPRECATED);
to Codeigniter folder \system\database\drivers\mysql\mysql_driver.php

open mysql_driver.php and add the above script to line 134. So your edited mysql_driver.php become like this
 
 

Tuesday, June 5, 2018

[SOLVED] PHP Permutation of given words with all posibilities of combination



If you want to create a permutation with all posibilities of words in PHP, you can use the following script

if(isset($_POST['submit'])){
    $data      = $_POST['data'];
    $arr = explode(' ',$data);
    permutasikan($arr);
}
function permutasikan($items, $perms = array()) {
    if (empty($items)) {
        echo join(' ', $perms) . "\n";
    } else {
        for ($i = count($items) - 1; $i >= 0; --$i) {
             $newitems = $items;
             $newperms = $perms;
             list($foo) = array_splice($newitems, $i, 1);
             array_unshift($newperms, $foo);
             permutasikan($newitems, $newperms);
         }
    }
}