0

Hello I have some data in mysql table, like this:

name----cake----image_design

explosion----cheesecake----images/cake/sofia.png

I have all images of the designs in a folder (/cake)

In my php document I get the data:

<?php
    session_start();
    include "../config/config.php";//Contiene funcion que conecta a la base de datos
    if (!isset($_SESSION['user_id'])&& $_SESSION['user_id']==null) {

       // header("location: index.php");
    }
    $id_conect=$_SESSION['user_id'];
    $query3=mysqli_query($con, "SELECT * from user where id='$id_conect'");
     while ($rs=mysqli_fetch_array($query3)) 
     {
     $tipo=$rs['tipo'];
     }
    $action = (isset($_REQUEST['action']) && $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
    if (isset($_GET['id'])){
        $id_del=intval($_GET['id']);
        $query=mysqli_query($con, "SELECT * from pedido where id_pedido='".$id_del."'");
        $count=mysqli_num_rows($query);

            if ($delete1=mysqli_query($con,"DELETE FROM pedido WHERE id_pedido='".$id_del."'")){
?>
            <div class="alert alert-success alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <strong>Aviso!</strong> Datos eliminados exitosamente.
            </div>
        <?php 
            }else {
        ?>
                <div class="alert alert-danger alert-dismissible" role="alert">
                  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <strong>Error!</strong> Lo siento algo ha salido mal intenta nuevamente.
                </div>
    <?php
            } //end else
        } //end if
    ?>

<?php
    if($action == 'ajax'){
        // escaping, additionally removing everything that could be (html/javascript-) code
         $q = mysqli_real_escape_string($con,(strip_tags($_REQUEST['q'], ENT_QUOTES)));
         $aColumns = array('cliente');//Columnas de busqueda
         $sTable = "pedido";
         $sWhere = "";
        if ( $_GET['q'] != "" )
        {
            $sWhere = "WHERE (";
            for ( $i=0 ; $i<count($aColumns) ; $i++ )
            {
                $sWhere .= $aColumns[$i]." LIKE '%".$q."%' OR ";
            }
            $sWhere = substr_replace( $sWhere, "", -3 );
            $sWhere .= ')';
        }
        $sWhere.=" order by created_at desc";
        include 'pagination.php'; //include pagination file

        //pagination variables

        $page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
        $per_page = 10; //how much records you want to show
        $adjacents  = 4; //gap between pages after number of adjacents
        $offset = ($page - 1) * $per_page;
        //Count the total number of row in your table*/
        $count_query   = mysqli_query($con, "SELECT count(*) AS numrows FROM $sTable  $sWhere");
        $row= mysqli_fetch_array($count_query);
        $numrows = $row['numrows'];
        $total_pages = ceil($numrows/$per_page);
        $reload = './expences.php';
        //main query to fetch the data
        $sql="SELECT * FROM  $sTable $sWhere LIMIT $offset,$per_page";

                        if($tipo==1|| $tipo==3)
                    {
                    $query = mysqli_query($con, $sql);
                    }else 
                    {
                    $query=mysqli_query($con, "select * from pedido where id_usuario= $id_conect");
                    }
        //loop through fetched data
        if ($numrows>0){

            ?>
            <table class="table table-striped jambo_table bulk_action">
                <thead>
                    <tr class="headings">
                        <th class="column-title">Cliente </th>
                        <th>Fecha</th>
                        <th class="column-title">Tienda </th>


                        <th class="column-title no-link last"><span class="nobr"></span></th>
                    </tr>
                </thead>
                <tbody>
                <?php 

                        while ($r=mysqli_fetch_array($query)) {
                            $id=$r['id_pedido'];
                           $created_at=date('Y-m-d H:i:s', strtotime($r['created_at']));
//                            $description=$r['description'];
//                            $nombre=$r['nombre_ticket'];
//                            $solucion=$r['solucion'];
//                            $soporte=$r['soporte'];
//                            $title=$r['title'];
//                            $priority_id=$r['priority_id'];
                              $status_id=$r['id_status'];
//                            $kind_id=$r['kind_id'];
//                            $category_id=$r['category_id'];
                              $Cliente=$r['cliente'];
                              $project_id=$r["project_id"];
                              $encargada=$r["nombre_pedido"];
                              $producto_id=$r["id_producto"];
                              $cantidad=$r["cantidad"];
                              $biscocho=$r["biscocho"];
                              $relleno=$r["id_relleno"];
                              $design=$r["id_design"];
                              $opcion=$r["opcion"];
                              $observacion=$r["observacion"];
                              $dedicatoria=$r["dedicatoria"];
                              $c_fondo=$r["color_fondo"];
                              $c_chongo=$r["color_chongo"];
                              $c_rosas=$r["color_rosas"];
                              $figura=$r["figura"];
                              $c_figura=$r["color_figura"];
                              $hora=$r["hora"];
                              $cliente=$r["cliente"];
                              $telefono=$r["telefono"];
                              $entrega   =$r['fecha_entrega'];
                              $imagen   =$r["id_design"];

                            $sql = mysqli_query($con, "select * from project where id=$project_id");
                            if($c=mysqli_fetch_array($sql)) {
                                $name_project=$c['name'];
                            }

//                            $sql = mysqli_query($con, "select * from priority where id=$priority_id");
//                            if($c=mysqli_fetch_array($sql)) {
//                                $name_priority=$c['name'];
//                            }

                            $sql = mysqli_query($con, "select * from status where id=$status_id");
                            if($c=mysqli_fetch_array($sql)) {
                                $name_status=$c['name'];
                            }


                ?>
                    <input type="hidden" value="<?php echo $id;?>" id="id<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $created_at;?>" id="fecha<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $project_id;?>" id="project_id<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $Cliente;?>" id="cliente<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $encargada;?>" id="encargada<?php echo $id;?>">
                    <!-- me obtiene los datos -->
                    <input type="hidden" value="<?php echo $producto_id;?>" id="producto_id<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $cantidad;?>" id="cantidad<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $biscocho;?>" id="biscocho<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $relleno;?>" id="relleno<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $design;?>"  id="design<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $status_id;?>" id="status_id<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $opcion;?>" id="opcion<?php echo $id;?>">
                    <input type="hidden" value="<?php echo $observacion;?>" id="observacion<?php echo $id?>">
                    <input type="hidden" value="<?php echo $dedicatoria;?>" id="dedicatoria<?php echo $id?>">
                    <input type="hidden" value="<?php echo $c_fondo;?>" id="c_fondo<?php echo $id?>">
                    <input type="hidden" value="<?php echo $c_chongo;?>" id="c_chongo<?php echo $id?>">
                    <input type="hidden" value="<?php echo $c_rosas;?>" id="c_rosas<?php echo $id?>">
                    <input type="hidden" value="<?php echo $figura;?>"  id="figura<?php echo $id ?>">
                    <input type="hidden" value="<?php echo $entrega;?>"  id="entrega<?php echo $id ?>">
                    <input type="hidden" value="<?php echo $hora;?>"  id="hora<?php echo $id ?>">
                    <input type="hidden" value="<?php echo $cliente;?>"  id="cliente<?php echo $id ?>">
                    <input type="hidden" value="<?php echo $telefono;?>"  id="telefono<?php echo $id ?>">
                    <input type="hidden" value="<?php echo $imagen;?>"  id="imagen<?php echo $id ?>">



                    <tr class="even pointer">
                        <td><?php echo $cliente;?></td>
                        <td><?php echo $created_at;?></td>
                        <td><?php echo $project_id;?></td>


                        <td ><span class="pull-right">
                        <a href="#" class='btn btn-default' title='Consultar Pedido' onclick="obtener_datos('<?php echo $id;?>');" data-toggle="modal" data-target=".bs-example-modal-lg-udp"><i class="glyphicon glyphicon-edit"></i></a> 
        </span></td>
                    </tr>
                <?php
                    } //en while
                ?>
                <tr>
                    <td colspan=6><span class="pull-right">
                        <?php echo paginate($reload, $page, $total_pages, $adjacents);?>
                    </span></td>

                </tr>
              </table>
            </div>
            <?php
        }else{
           ?> 
            <div class="alert alert-warning alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <strong>Aviso!</strong> No hay datos para mostrar!
            </div>
        <?php    
        }
    }
?>

Then in another archive.php, I receive the variables like this:

<script>
    function obtener_datos(id){
        var soporte = $("#soporte"+id).val();
        var encargada = $("#encargada"+id).val();
        var producto_id = $("#producto_id"+id).val();
        var cantidad = $("#cantidad"+id).val();
        var biscocho = $("#biscocho"+id).val();
        var relleno  = $("#relleno"+id).val();
        var design   = $("#design"+id).val();
        var opcion   = $("#opcion"+id).val();
        var observacion =$("#observacion"+id).val();
        var dedicatoria =$("#dedicatoria"+id).val();
        var c_fondo  = $("#c_fondo"+id).val();
        var c_chongo =$("#c_chongo"+id).val();
        var c_rosas  =$("#c_rosas"+id).val();
        var figura   =$("#figura"+id).val();
        var entrega  =$("#entrega"+id).val();
        var hora  =$("#hora"+id).val();
        var cliente  =$("#cliente"+id).val();
        var telefono  =$("#telefono"+id).val();
        var kind_id = $("#kind_id"+id).val();
        var project_id = $("#project_id"+id).val();
        var category_id = $("#category_id"+id).val();
        var priority_id = $("#priority_id"+id).val();
        var status_id = $("#status_id"+id).val();
        var imagen  =$("#imagen"+id).val();
            $("#mod_id").val(id);
            $("#mod_encargada").val(encargada);
            $("#mod_producto_id").val(producto_id);
            $("#mod_cantidad").val(cantidad);
            $("#mod_biscocho").val(biscocho);
            $("#mod_relleno").val(relleno);
            $("#mod_design").val(design);
            $("#mod_opcion").val(opcion);
            $("#mod_observacion").val(observacion);
            $("#mod_dedicatoria").val(dedicatoria);
            $("#mod_c_fondo").val(c_fondo);
            $("#mod_c_chongo").val(c_chongo);
            $("#mod_c_rosas").val(c_rosas);
            $("#mod_figura").val(figura);
            $("#mod_entrega").val(entrega);
            $("#mod_hora").val(hora);
            $("#mod_cliente").val(cliente);
            $("#mod_telefono").val(telefono);
            $("#mod_soporte").val(soporte);
            $("#mod_kind_id").val(kind_id);
            $("#mod_project_id").val(project_id);
            $("#mod_category_id").val(category_id);
            $("#mod_priority_id").val(priority_id);
            $("#mod_status_id").val(status_id);
            $("#mod_imagen").val(imagen);
        }

</script>

Below #mod_name and #mod_cake is the id of text box.

    <div class="col-md-9 col-sm-9 col-xs-12">
                      <input type="text" style="width:150px; float:left;"name="encargada" id="**mod_cake**"class="form-control">
                            </div>  
                            </div>
                        </div>

Now my problem is with the image, because return me images/cake/sofia.png and I don't know how I show that image I try with this:

    <img id ="mod_imagen"src="">

but does not work.

2 Answers2

0

Having the image itself in you database may slow down your queries. Instead, consider storing the image name in the database and the image itself as you usually would: a file in a directory. Then, with Javascript:

document.getElementById("**mod_cake**").src = "<?php echo $filename; ?>";
Adam Winter
  • 1,680
  • 1
  • 12
  • 26
0

i solve that wiht this:

javascript:

    var imagen  =$("#imagen"+id).val();
    document.getElementById("imagenid").src=imagen;

other php:

<img id="imagenid"src="" />