SQL query with PHP

0

I am editing a reservation system with PHP and I want to make some inquiries. I have 3 Tables

w_clases

w_clientes

w_reservas

In summary I am trying to make a query with a form that puts the start date and end date and show it to me, I have this for the query:

SELECT cl.nombre,c.nombre From w_reservas R 
INNER JOIN wp_clases cl on R.id_clase =cl.id 
INNER JOIN w_clientes c on cl.id = r.id_usuario 
WHERE r.fecha_reserva BETWEEN '2014-01-01' AND '2017-01-01'

But I can not get it to work, in summary in the query I want it to appear:

Nombre clase | Fecha Clase | Hora clase | Nombre Usuario
-------------|-------------|------------|---------------
    
asked by Jesús 17.04.2017 в 23:33
source

2 answers

0

Try this:

SELECT cl.nombre,c.nombre From w_reservas r 
INNER JOIN wp_clases cl on r.id_clase =cl.id 
INNER JOIN w_clientes c on c.id = r.id_usuario 
WHERE r.fecha_reserva BETWEEN '2014-01-01' AND '2017-01-01'
    
answered by 17.04.2017 в 23:47
0

I think what you're looking for is:

select
    nombre_clase = cl.nombre,
    fecha_clase = r.fecha_reserva,
    hora_clase = cl.hora,
    nombre_usuario = c.nombre,
    apellidos_usuario = c.apellidos
from
    w_reservas r
    inner join w_clases cl on
        cl.id = r.id_clase
    inner join w_clientes c on
        c.id = r.id_usuario
where
    r.fecha_reserva between '2014-01-01' and '2017-01-01'
order by
    r.fecha_reserva, r.id_clase, c.nombre, c.apellidos
    
answered by 17.04.2017 в 23:52