Welcome Guest, Not a member yet? Register   Sign In
I want to convert this Core PHP code to Codeignitor Framework
#1

(This post was last modified: 08-16-2018, 10:05 PM by ciadmin.)

I m new in code ignitor and i learn codeignitor fremework please help me for convert below code to codeignitor framework format.

Thanks in advance....

Code:
HEADER LINKS

    
   

    <link href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet">
        <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
        <!-- Script -->
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
       
    HTML CODE
   
   

    <!-- Begin page content -->
        <div class="container content-invoice">
        <h1 class="text-center title">jQuery UI Autocomplete 2 Fields</h1>
        <h1>&nbsp;</h1>
        <form method="post">
        <div class="row">
        <div  class="col-xs-12 col-sm-offset-1 col-md-offset-1 col-lg-offset-1 col-sm-3 col-md-3 col-lg-3  ">
        <div class="form-group">
        <input type="text" placeholder="Company Name" id="clientCompanyName" name="data[clientCompanyName]" class="form-control ui-autocomplete-input" value="" autocomplete="off">
        </div>
        </div>
        <div  class="col-xs-12 col-sm-3 col-md-3 col-lg-3  text-center">
        <button type="button" id="myButton" class="btn btn-success" autocomplete="off" style="display: none">
          Loading....
        </button>
        </div>
        <div  class="col-xs-12 col-sm-3 col-md-3 col-lg-3 ">
        <div class="form-group">
        <textarea placeholder="Your Address" id="clientAddress" name="data[clientAddress]" rows="3" class="form-control txt"></textarea>
        </div>
        </div>
        </div>
        </form>
        </div>
   
   
    
    SCRIPT
    
    <script>
        $('#clientCompanyName').autocomplete({
            source: function( request, response ) {
            $.ajax({
            url : 'http://localhost/demo/6/ouders/ajax',
            dataType: "json",
            method: 'post',
            data: {
            name_startsWith: request.term,
            type: 'customerName'
            },
            success: function( data ) {
            response( $.map( data, function( item ) {
            var code = item.split("|");
            return {
            label: code[1],
            value: code[1],
            data : item
            }
            }));
            }
            });
            },
            autoFocus: true,      
            minLength: 1,
            select: function( event, ui ) {
                $('#myButton').show();
            var names = ui.item.data.split("|");
            $(this).val(names[1]);
            getClientAddress(names[0]);
            }      
           });
        </script>



AJAX.PHP



    <?php
    /*
    Site : http:www.smarttutorials.net
    Author :muni
    */
    require_once 'config.php';
    
    if(isset($_POST['type']) && $_POST['type'] == 'customerName' ){
    $type = $_POST['type'];
    $name = $_POST['name_startsWith'];
    $query = "SELECT id, customerName FROM customers where UPPER($type) LIKE '%".strtoupper($name)."%'";
    $result = mysqli_query($con, $query);
    $data = array();
    while ($row = mysqli_fetch_assoc($result)) {
    $name = $row['id'].'|'.$row['customerName'];
    array_push($data, $name);
    }
    mysqli_close($con);
    echo json_encode($data);exit;
    }
    
    if(isset($_POST['type']) && $_POST['type'] == 'clientAddress' ){
    $id = $_POST['id'];
    $query = "SELECT id, addressLine1, addressLine2, city, state, country, phone FROM customers WHERE id =$id";
    $result = mysqli_query($con, $query);
    $data = mysqli_fetch_assoc($result);
    $address = '';
    if(!empty( $data )){
    $address = isset($data['addressLine1'])? $data['addressLine1'].',
' : '';
    $address .= isset($data['addressLine2'])? $data['addressLine2'].',
': '';
    $city = isset($data['city'])? $data['city']: '';
    $state = isset($data['state'])? $data['state']: '';
    $country = isset($data['country'])? $data['country']: '';
    $phone = isset($data['phone'])? $data['phone']: '';
    $address .=$city.','.$state.',
';
    $address .=$country.',
';
    $address .=$phone.'.';
   
    }
    mysqli_close($con);
    echo $address;exit;
    }


CONFIG.PHP


    <?php
    /*
    Site : http:www.smarttutorials.net
    Author :muni
    */
    //site specific configuration declartion
    define( 'BASE_PATH', 'http://localhost/demo/7/');
    define('DB_HOST', 'localhost');
    define('DB_NAME', 'smart_invoice');
    define('DB_USERNAME','root');
    define('DB_PASSWORD','');
    
    
    $con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
    if( mysqli_connect_error()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
    
    define( 'CURRENT_YEAR', date("Y"));



Database



    --
    -- Table structure for table `customers`
    --
    
    CREATE TABLE `customers` (
      `id` int(11) NOT NULL,
      `customerName` varchar(255) NOT NULL,
      `addressLine1` varchar(255) NOT NULL,
      `addressLine2` varchar(255) NOT NULL,
      `city` varchar(255) NOT NULL,
      `state` varchar(255) NOT NULL,
      `country` varchar(255) NOT NULL,
      `phone` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `customers`
    --
    
    --
    -- Indexes for table `customers`
    --
    ALTER TABLE `customers`
      ADD PRIMARY KEY (`id`);
    
    --
    -- AUTO_INCREMENT for dumped tables
    --
** code tags because the post goes on & on **
Reply
#2

Hi

I would suggest you read the manual and use the  tutorial  it covers everything to convert your sample code.

Best of luck.
A good decision is based on knowledge and not on numbers. - Plato

Reply




Theme © iAndrew 2016 - Forum software by © MyBB