upload image through ajax jquery php codeigniter

    public function save_product_detail_image($idproduct)
    {
        if (isset($_POST['image'])) {

            $imageData = $_POST['image'];

            list($type, $imageData) = explode(';', $imageData);
            list(,$extension) = explode('/',$type);
            list(,$imageData)      = explode(',', $imageData);
            $fileName = uniqid().'.'.$extension;
            $imageData = base64_decode($imageData);
            file_put_contents('assets/produkt_images0/'.$fileName, $imageData);

            if ($_POST['id_file_type'] == "master_img") {

                $this->db->where("id_product", $idproduct)
                ->where('id_file_type', 'master_img')
                ->delete('file');
            }
            else if ($_POST['id_file_type'] == "product_featured_img") {

                $this->db->where("id_product", $idproduct)
                ->where('id_file_type', 'product_featured_img')
                ->delete('file');
            }

            $file_produkt_image = array(
                "id_file_type" => $_POST['id_file_type'],
                "id_product" => $idproduct,
                "is_active" => 1,
                "file_name" => "assets/produkt_images0/" . $fileName,
                "thumb_name" => "assets/produkt_thumb0/" . $fileName,
                "file_description" => 'hl. obrazek produktu',
                "created_by" => 2,
                'modified_by' => 2
            );

            $this->db->insert('file', $file_produkt_image);

            return $fileName;
 
        }
    }

[php] Breadcrumbs for Codeigniter in the helper function

function _breadcrumbs()
{
    $ci = & get_instance();
    $urlSegment = $ci->uri->segment_array();

    if (($key = array_search("product", $urlSegment)) !== false) {
        unset($urlSegment[$key]);
    }
    if (($key = array_search("products", $urlSegment)) !== false) {
        unset($urlSegment[$key]);
    }
    if (($key = array_search("product-category", $urlSegment)) !== false) {
        unset($urlSegment[$key]);
    }

    // print_r($urlSegment);

    $breadcrumbs = '<div class="row">
            <div class="col-sm-12">
                <p class="breadcrumb"><a href="" title=""><img src="' . base_url() .'assets/frontend/img/home.svg" alt="" /></a> ';

    foreach ($urlSegment as $key => $segment) {
        $breadcrumbs .= '<img src="'. base_url() .'assets/frontend/img/gt.png" alt="" /> '. ucfirst($segment) . ' ';
    }

    $breadcrumbs .= '</p>
            </div>
        </div>';

    echo $breadcrumbs;
}

Ajax Search PHP through MySQL record


var searchRequest = null;

$(function () {
    var minlength = 3;

    $("#spedostech_search").keyup(function () {
        var that = this,
        value = $(this).val();

        if (value.length >= minlength ) {
            if (searchRequest != null) 
                searchRequest.abort();

            console.log( );
            // return;
            
            searchRequest = $.ajax({
                type: "GET",
                url: BASE_URL + "spedostech/search",
                data: {
                    'search_keyword' : value
                },
                dataType: "json",
                success: function(msg){
                    // var obj = JSON.stringify(msg);
                    console.log(msg);
                    //we need to check if the value is the same
                    if (value==$(that).val()) {
                        var container = $('<ul />');
                        $.each( msg, function( section, List ) {
                          var li = $('<li>Nalezeno v '+section+' (3)</li>');

                          // container.append('<li>Nalezeno v '+section+' (3)</li>');
                          // console.log( section + " : ");
                          var ul = $('<ul />');
                          $.each( List, function( key, item ) {
                            ul.append('<li><a href="#'+item.id+'" title="">'+item.name+'</a></li>');
                            // console.log("Name : " + item.name);
                          });
                          li.append(ul);
                          container.append(li);  
                        });

                    // console.log(container);
                        // $('#tt').html(container);
                        $('#search-whisperer').html(container);

                    //Receiving the result of search here
                    }
                }
            });
        }
    });
});



[PHP] Dynamic Breadcrumb for tracing navigation

Hello, This is the code for Breadcrumb class.


class Breadcrumb
{

    public function getBreadcrumb($code){

        $bc = [];

        while( $code != '1' ){


            $sql = "SELECT PAR,NAME,CODE FROM global_tbl WHERE CODE =" . $code;
            $instance = db_query($sql);

            $row = mysqli_fetch_array($instance);

            $bc[] = [
                'parent' => $row['PAR'],
                'code' => $row['CODE'],
                'name' => $row['NAME']
            ];

            $code = $row['PAR'];
        }

        krsort($bc);

        return $bc;

    }


}

$bc = new Breadcrumb();

$breadcrumb = $bc->getBreadcrumb($_GET['parentCode']);

// this is for using this breadcrumb though html.
<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">
            Forms
        </h1>
        <ol class="breadcrumb">
            <li>
                <i class="fa fa-dashboard"></i>  <a href="index.html">Dashboard</a>
            </li>

            <?php

            foreach($breadcrumb as $bc):
            ?>

            <li class="">
                <a href="entryDataGlobalTable.php?parentCode=<?= $bc['code'] ?>">
                    <i class="fa fa-edit"></i> <?= $bc['name'] ?>
                </a>
            </li>
            <?php endforeach; ?>
        </ol>
    </div>
</div>

How to add table row in jquery+javascript

just paste this code … in the script section .. make sure your “id” is properly matched … otherwise it wont work .

.
.
var itemserial = document.getElementById('labitemsn').value = 1;

function deleteRow(id){
	
	var row = document.getElementById('rowbody');
	var delrownum = document.getElementById('item' + id);
	row.removeChild(delrownum);
}


$(function(){

	itemserial = 1;

	$('#itemadd').click(function(){
		
		var labitesn = document.getElementById('labitemsn').value;
		var labitemname = document.getElementById('labitemname').value;
		var labitemmrp = document.getElementById('labitemmrp').value;
		var labitemqty = document.getElementById('labitemqty').value;
		var labmrptotal = document.getElementById('labmrptotal').value;

		if(!labitemname || !labitemmrp || !labitemqty || !labmrptotal){
			alert("Required Information Need to Fill Up.");
			return false;
		}

		var labitems = document.getElementById('labitems');
		labitems.style.visibility = "visible";
		
		var row =   document.createElement('tr');
		row.id = "item"+itemserial;
		row.name = "item"+itemserial;

		var column = document.createElement('td');
		column.id = "labitemsn"+itemserial;
		column.name = "labitemsn"+itemserial;
		var text = document.createTextNode(itemserial);
		column.appendChild(text);
		row.appendChild(column);

		var column = document.createElement('td');
		column.id = "labitemname"+itemserial;
		column.name = "labitemname"+itemserial;
		var text = document.createTextNode(labitemname);
		column.appendChild(text);
		row.appendChild(column);

		var column = document.createElement('td');
		column.id = "labitemmrp"+itemserial;
		column.name = "labitemmrp"+itemserial;
		var text = document.createTextNode(labitemmrp);
		column.appendChild(text);
		row.appendChild(column);

		var column = document.createElement('td');
		column.id = "labitemqty"+itemserial;
		column.name = "labitemqty"+itemserial;
		var text = document.createTextNode(labitemqty);
		column.appendChild(text);
		row.appendChild(column);

		var column = document.createElement('td');
		column.id = "labmrptotal"+itemserial;
		column.name = "labmrptotal"+itemserial;
		var text = document.createTextNode(labmrptotal);
		column.appendChild(text);
		row.appendChild(column);

		var column = document.createElement('td');
		column.id = "labitemdlt"+itemserial;
		var span = document.createElement('span');
		span.className = "glyphicon glyphicon-trash";
		alert(itemserial);
		span.setAttribute("onclick","deleteRow("+ itemserial +")")
		
		column.appendChild(span);
		row.appendChild(column);

		var rowbody = document.getElementById('rowbody');
		rowbody.appendChild(row);

		itemserial++;
		document.getElementById('labitemsn').value = itemserial;
		document.getElementById('labitemname').value = '';
		document.getElementById('labitemmrp').value = '';
		document.getElementById('labitemqty').value = '';
		document.getElementById('labmrptotal').value = '';


	
	});


	$('#btn-invoice-submit').click(function(){
		
		if( parseInt(itemserial) &lt; 2 ){
			alert('Empty Item cannot be submitted..');
		}
	});

	

});