When I give in my onclick event sending a date I am left

-1

It happens that I am developing a system in php and the result of a query is this:

<?php
$data = '<table class="table table-striped">
                    <tr>
                        <th>ID</th>
                        <th>Conductor</th>
                        <th>Precio</th>
                        <th>Fecha</th>
                        <th>Acciones</th>
                    </tr>';



//if (!$result = mysql_query($query)) {
   // exit(mysql_error());
//}

// if query results contains rows then featch those rows 
if(isset($_POST['i_conductor']))
{
    $i_conductor = $_POST['i_conductor'];
    $query = mysql_query("SELECT c.id_conductor,c.nombre_conductor,c.apellido_conductor,SUM(s.precio) AS precio,s.fecha_servicio FROM servicios s INNER JOIN conductor c ON s.id_conductor = c.id_conductor WHERE c.id_conductor = $i_conductor GROUP BY s.fecha_servicio"); 

    while($row = mysql_fetch_array($query))
    {

        $id_conductor = $row["id_conductor"];
        $conductor = $row["nombre_conductor"]. " " .$row["apellido_conductor"];
        $precio = $row["precio"];
        $fecha = $row["fecha_servicio"];
        $fecha_format = strtotime($fecha);
        $fecha_format2 = date('d-m-Y',$fecha_format);

        $data .= '<tr>
            <td id="detalle_conductor" name="detalle_conductor" value='.$id_conductor.'>'.$id_conductor.'</td>
            <td>'.$conductor.'</td>
            <td>'.$precio.'</td>
            <td id="detalle_conductor_fecha" name="detalle_conductor_fecha" value='.$fecha.'>'.$fecha_format2.'</td>
            <td>
                <button type="button" id="fecha_servicio" name="fecha_servicio" value='.$fecha.' onclick="DetalleIngresos('.$id_conductor.','.$fecha.')"  class="btn btn-borders btn-primary mr-xs mb-sm">Ver Detalles</button>
            </td>
        </tr>';
    }
}
else
{
    // records now found 
    $data .= '<tr><td colspan="6">No existe ningun dato!</td></tr>';
}

$data .= '</table>';

echo $data;

However, as you can see, there is a onclick() with two parameters, one is an id, and the other is a date, it happens that when the page loads everything is fine, even if I give F12 for see if I pass the variable I see that in onclick says DetailIngresos (2,2017-12-15) but when I do click , that date transforms it in 1990, meaning those "-" takes it as if they were subtraction. So how do I do it, because that date I need it so that when click takes me to another query I pass it from AJAX to PHP where the date is an important parameter and it's as if in the where I said 1990 but I need 2017-12-15.

Here is my code JAVASCRIPT of DetailInsidences ():

function DetalleIngresos(d_id_conductor,d_fecha) {
d_fecha_ingresos = d_fecha;
$("#hidden_user_id").val(d_id_conductor);
$("#hidden_user_fecha").val(d_fecha_ingresos);
$.post("ajax/reportes/detalle_ingresos_conductor.php", {
        detalle_conductor : d_id_conductor,
        detalle_conductor_fecha : d_fecha,
    },
    function (data, status) {
        $(".mostrar_detalle_ingresos_por_conductor").html(data);
    }
);
// Open modal popup
$("#detalle_ingresos_modal").modal("show");
}

And this is the query you make in PHP :

<?php
// include Database connection file 
    include("abrir_conexion.php");

    $data = '<table class="table table-striped">
                    <tr>
                        <th>ID Servicio</th>
                        <th>Precio</th>
                        <th>Fecha</th>
                    </tr>';

if(isset($_POST['detalle_conductor']) && isset($_POST['detalle_conductor_fecha']))
{
    $detalle_conductor = $_POST['detalle_conductor'];
    $d_fecha_ingresos = $_POST['detalle_conductor_fecha'];

    $query = mysql_query("SELECT s.id_servicio,s.precio,s.fecha_servicio FROM servicios s INNER JOIN conductor c ON s.id_conductor = c.id_conductor WHERE c.id_conductor = $detalle_conductor AND s.fecha_servicio = '$d_fecha_ingresos' "); 

    while($row = mysql_fetch_array($query))
    {

        $id_servicio = $row["id_servicio"];
        $precio = $row["precio"];
        $fecha = $row["fecha_servicio"];
        $fecha_format = strtotime($fecha);
        $fecha_format2 = date('d-m-Y',$fecha_format);

        $data .= '<tr>
            <td>'.$id_servicio.'</td>
            <td>'.$precio.'</td>
            <td>'.$fecha_format2.'</td>
        </tr>';
    }
}
else
{
    // records now found 
    $data .= '<tr><td colspan="6">No existe ningun dato!</td></tr>';
}

$data .= '</table>';

echo $data;
?>
    
asked by Jhorvy 05.01.2018 в 08:22
source

3 answers

0

Try to enclose the date in quotes, just like the raisin will never work. The result should be something like the following:

DetailIncome (2, '2017-12-15')

    
answered by 05.01.2018 в 09:20
0

First try changing the button in this way and tell me if your problem has been solved:

<button type="button" id="fecha_servicio" name="fecha_servicio" value='.$fecha.' onclick="DetalleIngresos('.$id_conductor.',\"'.$fecha.'\")"  class="btn btn-borders btn-primary mr-xs mb-sm">Ver Detalles</button>

Or else:

<button type="button" id="fecha_servicio" name="fecha_servicio" value='.$fecha.' onclick="DetalleIngresos('.$id_conductor.',\''.$fecha.'\')"  class="btn btn-borders btn-primary mr-xs mb-sm">Ver Detalles</button>
    
answered by 05.01.2018 в 09:24
0

I would recommend making a couple of changes.

In your PHP , when creating the button, to pass parameters, enclose the date in quotes

<button type="button" id="fecha_servicio" name="fecha_servicio" value='.$fecha.' onclick="DetalleIngresos('.$id_conductor.',\''.$fecha.'\')"  class="btn btn-borders btn-primary mr-xs mb-sm">Ver Detalles</button>

In your JavaScript , try to define the date type variable

var d_fecha_ingresos = new Date('d_fecha');
    
answered by 05.01.2018 в 10:47