View Full Version : I want to list upcoming events stored in database for the next 15 days


mxarievilo
12-07-2009, 09:23 AM
But I'm not access developer and using PHP.

Isn't running becouse the original developer set data table field as a text.


<?php
//Eu preciso fazer uma consulta onde me mostre apenas os registros que irão vencer nos proximos 15 dias
// (I want to list upcoming events stored in database for the next 15 days)
$conexao = new COM("ADODB.Connection");
$conexao->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\wd\\negociofeito\\admin\\dat\\bd.mdb"); //conexão maquina local
$recordset = $conexao->Execute("select * from PRO where PRO_DTCAD > (NOW() - PRO_DURAC) AND PRO_DTCAD < (NOW()+15)"); //running, but not filtering
//$recordset = $conexao->Execute("select * from PRO"); // só a listagem rodando normal (OK)
echo "CÓDIGO" . " | " . "NOME" . " | " . "PREÇO" . " | " . "DATA CADASTRO" . " | " . "DURAÇÃO ANÚNCIO" . "<BR/>";
while (!$recordset->EOF) {
echo " | " . $recordset->fields["PRO_COD"]->value;
echo " | " . $recordset->fields["PRO_NOME"]->value;
echo " | " . $recordset->fields["PRO_PRECO"]->value;
echo " | " . $recordset->fields["PRO_DTCAD"]->value; //register data
echo " | " . $recordset->fields["PRO_DURAC"]->value; //duration
echo "<br/>";
$recordset->MoveNext();
}
$conexao->Close();
?>

WayneRyan
12-08-2009, 01:17 PM
mx,

This should get you started:


select *
from PRO
where CDate(PRO_DTCAD) Between DateAdd("d", -15, NOW()) AND DateAdd("d", 15, NOW())


hth,
Wayne

mxarievilo
12-09-2009, 01:56 AM
what "d" variable do?

------------------------------------------------------------

Parse error: syntax error, unexpected T_STRING in C:\wd\xampp\htdocs\nf\admin\consulta_vencendo.php on line 6

DCrake
12-09-2009, 02:00 AM
"d" is stipulating the difference in (d)ays do a F1 on DateAdd()

you may need to change it to single quotes.

David

mxarievilo
12-09-2009, 02:03 AM
$recordset = $conexao->Execute("select * from PRO where CDate(PRO_DTCAD) Between DateAdd(\"d\", -15, NOW()) AND DateAdd(\"d\", 15, NOW())");

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft JET Database Engine<br/><b>Description:</b> Tipo de dados imcompat&#237;vel na express&#227;o de crit&#233;rio.*****' in C:\wd\xampp\htdocs\nf\admin\consulta_vencendo.php: 6 Stack trace: #0 C:\wd\xampp\htdocs\nf\admin\consulta_vencendo.php( 6): com->Execute('select * from P...') #1 {main} thrown in C:\wd\xampp\htdocs\nf\admin\consulta_vencendo.php on line 6

*****Data type incompatible

DCrake
12-09-2009, 02:16 AM
What I would be tempted to do is to create the SQL execute string into a memvar then execute the memvar.

Dim sSQL as String

sSQL = "Select * from PRO where CDate(PRO_DTCAD) Between #" & DateAdd("d", -15, Date()) & "# AND #" & DateAdd("d", 15, Date()) & "#;"


$recordset = $conexao->Execute(sSQL)

David

mxarievilo
12-09-2009, 02:46 AM
DCrake,

I can't to declare Dim becouse is PHP isn't VBScript.
I think that this problem can be solved using STR_TO_DATE or looks like conversions...
But I can't to do because I'm an MSACCESS begginner and I can't to re-build the system.
I just need a new report.

And tanks, you are helping too.

The error is:
"Data type mismatch in criteria expression"

DCrake
12-09-2009, 03:06 AM
That error is telling me that there is nothing wrong with the actual syntax but what it is trying to evaluate is of the wrong data type.

If you take out the wher condition do it work then?

David

mxarievilo
12-09-2009, 04:04 AM
Whitout CDate conversion is running but is filtering empty.

http://negociofeito.com.br/admin/consulta_vencendo.php

I've an register added 31/10/2009

mxarievilo
12-09-2009, 04:07 AM
I'm trying this:

$recordset = $conexao->Execute("select * from PRO where CDate(PRO_DTCAD)+PRO_DURAC BETWEEN DateAdd(\"d\", +15, NOW()");

But:

PHP Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft JET Database Engine<br/><b>Description:</b> Missing ), ], or Item in query expression 'CDate(PRO_DTCAD)+PRO_DURAC BETWEEN DateAdd("d", +15, NOW()'.' in E:\...\consulta_vencendo.php:7
Stack trace:
#0 E:\...\consulta_vencendo.php(7): com->Execute('select * from P...')
#1 {main}
thrown in E:\...\consulta_vencendo.php on line 7