hookit Posted August 30, 2009 Share Posted August 30, 2009 Hi There is a textfiedl with date format yyyy/mm/dd and send matching queries to a database with same format. But if i validate the kind of format i want dd/mm/yyyy returns no results. Here is the php code: <?php require_once('Connections/soloporhoy.php'); ?> <?php if (isset($_GET['S_Fecha']) && ($_GET['S_Fecha']) == "") { $_GET['S_Fecha'] = "1/1/1"; } ?> <?php if (isset($_GET['S_Título']) && ($_GET['S_Título']) == "") { $_GET['S_Título'] = "-1"; } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php $currentPage = $_SERVER["PHP_SELF"]; ?> <?php if (!session_id()) session_start(); if (isset($_SESSION["soloporhoy_Results_QueryString"]) && ($_SESSION["soloporhoy_Results_QueryString"] != "") && !isset($_SERVER["QUERY_STRING"]) ){ header("Location: solopor hoy_Results.php?".str_replace("&totalRows_","&old_totalRows_",$_SESSION["soloporhoy_Results_QueryString"])); } else{$_SESSION["soloporhoy_Results_QueryString"] = isset($_SERVER["QUERY_STRING"])?$_SERVER["QUERY_STRING"]:""; } ?> <?php $maxRows_WADAsoloporhoy = 10; $pageNum_WADAsoloporhoy = 0; if (isset($_GET['pageNum_WADAsoloporhoy'])) { $pageNum_WADAsoloporhoy = $_GET['pageNum_WADAsoloporhoy']; } $startRow_WADAsoloporhoy = $pageNum_WADAsoloporhoy * $maxRows_WADAsoloporhoy; $ParamFecha_WADAsoloporhoy = "1/1/1"; if (isset($_GET['S_Fecha'])) { $ParamFecha_WADAsoloporhoy = $_GET['S_Fecha']; } $ParamFecha2_WADAsoloporhoy = "1/1/1"; if (isset($_GET['S_Fecha'])) { $ParamFecha2_WADAsoloporhoy = $_GET['S_Fecha']; } $ParamTítulo_WADAsoloporhoy = "-1"; if (isset($_GET['S_Título'])) { $ParamTítulo_WADAsoloporhoy = $_GET['S_Título']; } $ParamTítulo2_WADAsoloporhoy = "-1"; if (isset($_GET['S_Título'])) { $ParamTítulo2_WADAsoloporhoy = $_GET['S_Título']; } mysql_select_db($database_soloporhoy, $soloporhoy); $query_WADAsoloporhoy = sprintf("SELECT * FROM `solopor hoy` WHERE (Fecha = %s OR 1/1/1 = %s) AND (Título LIKE CONCAT('%%', %s, '%%') OR '-1' = %s)", GetSQLValueString($ParamFecha_WADAsoloporhoy, "date"),GetSQLValueString($ParamFecha2_WADAsoloporhoy, "date"),GetSQLValueString($ParamTítulo_WADAsoloporhoy, "text"),GetSQLValueString($ParamTítulo2_WADAsoloporhoy, "text")); $query_limit_WADAsoloporhoy = sprintf("%s LIMIT %d, %d", $query_WADAsoloporhoy, $startRow_WADAsoloporhoy, $maxRows_WADAsoloporhoy); $WADAsoloporhoy = mysql_query($query_limit_WADAsoloporhoy, $soloporhoy) or die(mysql_error()); $row_WADAsoloporhoy = mysql_fetch_assoc($WADAsoloporhoy); if (isset($_GET['totalRows_WADAsoloporhoy'])) { $totalRows_WADAsoloporhoy = $_GET['totalRows_WADAsoloporhoy']; } else { $all_WADAsoloporhoy = mysql_query($query_WADAsoloporhoy); $totalRows_WADAsoloporhoy = mysql_num_rows($all_WADAsoloporhoy); } $totalPages_WADAsoloporhoy = ceil($totalRows_WADAsoloporhoy/$maxRows_WADAsoloporhoy)-1; ?> <?php $queryString_WADAsoloporhoy = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_WADAsoloporhoy") == false && stristr($param, "totalRows_WADAsoloporhoy") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_WADAsoloporhoy = "&" . htmlentities(implode("&", $newParams)); } } $queryString_WADAsoloporhoy = sprintf("&totalRows_WADAsoloporhoy=%d%s", $totalRows_WADAsoloporhoy, $queryString_WADAsoloporhoy); ?> <?php //WA AltClass Iterator class WA_AltClassIterator { var $DisplayIndex; var $DisplayArray; function WA_AltClassIterator($theDisplayArray = array(1)) { $this->ClassCounter = 0; $this->ClassArray = $theDisplayArray; } function getClass($incrementClass) { if (sizeof($this->ClassArray) == 0) return ""; if ($incrementClass) { if ($this->ClassCounter >= sizeof($this->ClassArray)) $this->ClassCounter = 0; $this->ClassCounter++; } if ($this->ClassCounter > 0) return $this->ClassArray[$this->ClassCounter-1]; else return $this->ClassArray[0]; } } ?><?php //WA Alternating Class $WARRT_AltClass1 = new WA_AltClassIterator(explode("|", "WADAResultsRowDark|")); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Resultados de solopor hoy.</title> <link href="WA_DataAssist/styles/Refined_Pacifica.css" rel="stylesheet" type="text/css" /> <link href="WA_DataAssist/styles/TimesNewRoman.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- body,td,th { color: #FFFFFF; font-size: 16px; } body { background-color: #000099; } .style2 {padding-left: 6px; padding-right: 6px; vertical-align: middle;} .style3 {padding-top: 1px; padding-bottom: 1px; clear: both;} .style5 {font-size: 14} a:link { color: #CC0000; } .style6 { color: #00FF33; font-size: 12px; } a:visited { color: #FFFF00; } .style4 { font-size: 36px; font-style: italic; } .style7 { font-size: 18px; font-weight: bold; } .style8 {font-size: 16px; font-style: italic; } .style11 { font-size: 16px; color: #000000; } base { color: #FFFFFF; background-color: #666666; } .style13 {color: #333333} .style14 {font-size: 16px} .style16 {font-size: 14px} .style17 { font-size: 12 } --> </style> </head> <body> <div class="WADAResultsContainer"> <div class="WADAResultsHeader"> <div class="WADAHeaderText"> <p> </p> <p align="center"><img src="images/logoamor.png" alt="amor" width="105" height="109"></p> <p align="center" class="style4">EL PODER DEL AMOR</p> <p align="center" class="style4"><span class="style7"> Búsqueda de "Sólo por hoy"</span></p> <hr> <p align="center" class="style8"><u>Resultados de la Búsqueda.</u></p> </div> <div> <div align="center"><a href="solopor hoy_Search.php" class="style6 style16">Nueva Búsqueda.</a> </div> </div> </div> <div class="WADAHorizLine"> <div align="center"><img src="WA_DataAssist/images/Pacifica/Refined_tx.gif" alt="" height="1" width="1" border="0" /></div> </div> <div align="center"> <?php if ($totalRows_WADAsoloporhoy > 0) { // Show if recordset not empty ?> </div> <div class="WADAResults style5"> <div class="WADAResultsNavigation"> <div> <div align="center"> <p> </p> <p>Registros desde <?php echo ($startRow_WADAsoloporhoy + 1) ?> a <?php echo min($startRow_WADAsoloporhoy + $maxRows_WADAsoloporhoy, $totalRows_WADAsoloporhoy) ?>.<br> <br> </p> </div> </div> <div class="WADAResultsNavTop"> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" class="WADAResultsNavTable"> <tr valign="middle"> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy > 0) { // Show if not first page ?> <span class="style2" id="First"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, 0, $queryString_WADAsoloporhoy); ?>">Primero</a></span> <?php } // Show if not first page ?></td> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy > 0) { // Show if not first page ?> <span class="style2" id="Previous"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, max(0, $pageNum_WADAsoloporhoy - 1), $queryString_WADAsoloporhoy); ?>">Anterior</a> </span> <?php } // Show if not first page ?></td> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy < $totalPages_WADAsoloporhoy) { // Show if not last page ?> <span class="style2" id="Next"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, min($totalPages_WADAsoloporhoy, $pageNum_WADAsoloporhoy + 1), $queryString_WADAsoloporhoy); ?>">Siguiente</a> </span> <?php } // Show if not last page ?></td> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy < $totalPages_WADAsoloporhoy) { // Show if not last page ?> <span class="style2" id="Last"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, $totalPages_WADAsoloporhoy, $queryString_WADAsoloporhoy); ?>">Ultimo</a> </span> <?php } // Show if not last page ?></td> </tr> </table> <br> </div> </div> <div class="WADAResultsInsertButton"> </div> </div> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" bordercolor="#33FFFF" bgcolor="#FFFFFF" class="style3"> <tr> <th bgcolor="#000099" class="WADAResultsTableHeader style16">Fecha:</th> <th bgcolor="#000099" class="WADAResultsTableHeader style16">Título:</th> <th bgcolor="#000099" class="WADAResultsTableHeader style16">Vínculo:</th> <th bgcolor="#000099"> </th> </tr> <?php do { ?> <tr class="<?php echo $WARRT_AltClass1->getClass(true); ?>"> <td class="WADAResultsTableCell style11 style13 style14 style14"><?php echo($row_WADAsoloporhoy['Fecha']); ?></td> <td class="WADADataTableCell style11 style14"><?php echo($row_WADAsoloporhoy['Título']); ?></td> <td class="WADAResultsTableCell"><?php echo($row_WADAsoloporhoy['Vínculo']); ?></td> <td nowrap="nowrap" bgcolor="#000099" class="WADAResultsEditButtons"> </td> </tr> <?php } while ($row_WADAsoloporhoy = mysql_fetch_assoc($WADAsoloporhoy)); ?> </table> </div> <div class="WADAResultsNavigation"> <div> <div align="center"><br> Registros desde <?php echo ($startRow_WADAsoloporhoy + 1) ?> a <?php echo min($startRow_WADAsoloporhoy + $maxRows_WADAsoloporhoy, $totalRows_WADAsoloporhoy) ?> de un total de <?php echo $totalRows_WADAsoloporhoy ?> "Sólo por hoy".<br> </div> </div> <div class="WADAResultsNavBottom"> <div align="center"> <table border="0" cellpadding="0" cellspacing="0" class="WADAResultsNavTable"> <tr valign="middle"> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy > 0) { // Show if not first page ?> <span class="style2" id="First"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, 0, $queryString_WADAsoloporhoy); ?>">Primero.</a></span> <?php } // Show if not first page ?></td> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy > 0) { // Show if not first page ?> <span class="style2" id="Previous"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, max(0, $pageNum_WADAsoloporhoy - 1), $queryString_WADAsoloporhoy); ?>">Anterior</a> </span> <?php } // Show if not first page ?></td> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy < $totalPages_WADAsoloporhoy) { // Show if not last page ?> <span class="style2" id="Next"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, min($totalPages_WADAsoloporhoy, $pageNum_WADAsoloporhoy + 1), $queryString_WADAsoloporhoy); ?>">Siguiente</a> </span> <?php } // Show if not last page ?></td> <td class="WADAResultsNavButtonCell" nowrap="nowrap"><?php if ($pageNum_WADAsoloporhoy < $totalPages_WADAsoloporhoy) { // Show if not last page ?> <span class="style2" id="Last"> <a href="<?php printf("%s?pageNum_WADAsoloporhoy=%d%s", $currentPage, $totalPages_WADAsoloporhoy, $queryString_WADAsoloporhoy); ?>">Ultimo</a> </span> <?php } // Show if not last page ?></td> </tr> </table> </div> </div> </div> </div> <div align="center"> <?php } // Show if recordset not empty ?> <?php if ($totalRows_WADAsoloporhoy == 0) { // Show if recordset empty ?> </div> <div class="WADANoResults style5"> <div> <div align="center">Lo sentimos. No hay resultados. ¡Sigue buscando!</div> </div> <div> </div> </div> <div align="center"> <?php } // Show if recordset empty ?> </div> <hr> <p align="center"><a href="http://soloporhoy.1free.ws" class="style17">Página principal</a></p> </div> </body> </html> <?php mysql_free_result($WADAsoloporhoy); ?> Any help? Quote Link to comment https://forums.phpfreaks.com/topic/172468-date-format-in-database-query/ Share on other sites More sharing options...
ignace Posted August 30, 2009 Share Posted August 30, 2009 if (preg_match('/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/', $date)) Quote Link to comment https://forums.phpfreaks.com/topic/172468-date-format-in-database-query/#findComment-909269 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.