Forum Moderators: coopster

Message Too Old, No Replies

update mysql script

         

helenp

8:03 am on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi,
I have a mysql script that coopster helped me with in this thread: [webmasterworld.com...]
Itīs too old to open it again.
I have troubbles with it though the host updated mysql, and it does not work anymore.
The script is to get all movements and balance for one quarter selected, and to get previous balance for previous quarter.
This is the script:

$year = $_REQUEST['year'];
$month = $_REQUEST['month'];
$day = $_REQUEST['day'];
$date = $_REQUEST['date'];
$date = $year."-".$month."-".$day;
SELECT DATE_FORMAT(fecha, '%d-%m-%y') as ffecha, importe, pagado, servicios,DATE_FORMAT(llegada, '%e/%c') as fllegada, DATE_FORMAT(salida, '%e/%c') salida, TO_DAYS(salida) - TO_DAYS(llegada) as dias, propiedades.id_propiedad, cliente FROM propiedades LEFT JOIN bookings ON propiedades.id_reservas = bookings.id AND propiedades.id_propiedad = bookings.propiedad WHERE propiedades.id_propiedad = '$propiedad' and quarter(fecha) = quarter('$date') and year(fecha) = year('$date') order by fecha

select
sum(importe)
- sum(servicios)
-sum(pagado) as total_duenos
from propiedades WHERE propiedades.id_propiedad = '$propiedad' and fecha <= DATE_ADD('$date', INTERVAL -3 MONTH)",$dbh);

The date I get when they choose year and month (month 3, 6, 9 or 12) and the day is a hidden field
<input type="hidden" name="day" size="1" value="31">

The problem is with the value 31 for the days, if the quarter choosen has 30 days instead of 31 I do not get any results anymore....
So One way of fixing could be to take away the hidden day value and in the form choose the month with the day like this 03-31, 06-30 etc...
that works perfect for choosen one quarter, but dont work when I want the balance for previous quarter, though the way of counting previous quarters balance is
using DATE_ADD('$date', INTERVAL -3 MONTH. Doing that takes me to previous quarters balance to day 30 instead of 31 in some cases.... Donīt know how to fix this.
Please help, thanks
Helen

helenp

8:41 am on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Added, my new mysql version is 5.0.51a-community

I already tried to do this to get previous quarters balance <= DATE_ADD('$date', INTERVAL -1 QUARTER One some that works, on other quarter donīt give me the correct balance, seems to be depending on the days in the months.

helenp

9:07 am on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Lol,
It works now, with my fix, I had one date in the form wrong :)
Thanks for your attention.

deMorte

9:27 am on May 29, 2008 (gmt 0)

10+ Year Member



<ignore>
I'm not sure if I understand the question correctly, but aren't some quarters supposed to end on 30th day?
If you get the previous quarters balance on 3rd quarter, shouldn't the balance be from 1.4. to 30.6.?

One reason for wrong balance could be that if you supply an incorrect date for DATE_ADD (such as 2007-06-31) it returns null.

I don't know if this helped at all, maybe you could illustrate the problem a bit further.
</ignore>

[edited by: deMorte at 9:28 am (utc) on May 29, 2008]

helenp

10:06 am on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes that was the problem
It did work before the mysql update,
I fixed it eliminating the day value of 31, adding the last day of the quarter month to the month in the form.
Thanks anyway