Jun 17, 2020, updated at 07:38:23 (UTC)
2169
4
0
- Copy internal post link
- Copy external post link
- Report article
https://administrator.de/forum/input-type-als-text-und-date-format-579843.html
[content:579843]
Input type als Text und Date Format
Ich stehe hier etwas auf dem Schlauch:
Ich möchte in diesem Feld(zur Zeit "Text") auch nach einem deutschen Datum suchen, nur nimmt er hier immer das englische Format YYYY-MM-DD. Dann ist die Suche auch erfolgreich.
Dies ist mir auch klar. Im Textfeld nimmt er die Formatierung aus MySQL.
Ändere ich das Feld in "Date" funktioniert auch die Suche im deutschen Format (d.m.Y). Das Datum ist als 'date' in MySQL angelegt.
Das Suchfeld soll aber Text und das deutsche Datum nehmen, da über dieses Feld verschiedene Formen an Suchen stattfinden sollen.
Mit zwei Suchfeldern habe ich es probiert, geht auch, aber um es so einfach wie möglich zu machen, würde ich gerne nur ein Suchfeld benutzen.
Gibt es so ein Kombifeld? In meinen Recherchen war ich leider nicht erfolgreich.
Und dann gibt es noch ein kleines Problem. Die Sortierung nach Datum funktioniert hier nicht. $limit gibt die Anzahl der Datensätze pro Seite zurück.
Ich bitte um eure Hilfe.
<div class="post-search-panel">
<input type="text" id="keywords" placeholder="Suche..." onkeyup="searchFilter();"/>
<input id="reload" type="button" value="Neue Suche" onclick="javascript:location.reload();" />
<select id="sortBy" onchange="searchFilter();">
<option value="">Nach Datum sortieren</option>
<option value="asc">Aufsteigend</option>
<option value="desc">Absteigend</option>
</select>
</div>
Ich möchte in diesem Feld(zur Zeit "Text") auch nach einem deutschen Datum suchen, nur nimmt er hier immer das englische Format YYYY-MM-DD. Dann ist die Suche auch erfolgreich.
Dies ist mir auch klar. Im Textfeld nimmt er die Formatierung aus MySQL.
Ändere ich das Feld in "Date" funktioniert auch die Suche im deutschen Format (d.m.Y). Das Datum ist als 'date' in MySQL angelegt.
Das Suchfeld soll aber Text und das deutsche Datum nehmen, da über dieses Feld verschiedene Formen an Suchen stattfinden sollen.
Mit zwei Suchfeldern habe ich es probiert, geht auch, aber um es so einfach wie möglich zu machen, würde ich gerne nur ein Suchfeld benutzen.
Gibt es so ein Kombifeld? In meinen Recherchen war ich leider nicht erfolgreich.
Und dann gibt es noch ein kleines Problem. Die Sortierung nach Datum funktioniert hier nicht. $limit gibt die Anzahl der Datensätze pro Seite zurück.
$query = $db->query("SELECT DATE_FORMAT(Datum, '%d.%m.%Y') AS Datum
FROM table ORDER BY Datum ASC LIMIT $limit");
Ich bitte um eure Hilfe.
Please also mark the comments that contributed to the solution of the article
Content-Key: 579843
Url: https://administrator.de/contentid/579843
Printed on: April 26, 2024 at 09:04 o'clock
4 Comments
Latest comment
- Comment overview - Please log in
- Copy internal comment link
- Copy external comment link
- To the beginning of the comments
https://administrator.de/forum/input-type-als-text-und-date-format-579843.html#comment-1458643
[content:579843#1458643]
Hallo,
das ganze lässt sich in einem Feld abbilden, indem du anhand von Regular Expressions überprüfst, was dein Suchbegriff sein könnte.
bei deiner Sortierung musst du natürlich das sortBy Flag auswerten und dementsprechend deine qry anpassen
das ganze lässt sich in einem Feld abbilden, indem du anhand von Regular Expressions überprüfst, was dein Suchbegriff sein könnte.
$date="01.01.2020";
if (preg_match("/^(0[1-9]|1[0-2])\.(0[1-9]|[1-2][0-9]|3[0-1])\.([0-9]{4})$/",$date)) {
// Suche nach Datum
} else {
// Suche nach Text
}
bei deiner Sortierung musst du natürlich das sortBy Flag auswerten und dementsprechend deine qry anpassen
var sort = $sortBy === 'asc' ? 'ASC' : 'DESC';
$query = $db->query("SELECT ..... ORDER BY Datum $sortBy LIMIT $limit");
omroettger Jun 17, 2020 updated at 15:58:28 (UTC)
- Copy internal comment link
- Copy external comment link
- To the beginning of the comments
https://administrator.de/forum/input-type-als-text-und-date-format-579843.html#comment-1458851
[content:579843#1458851]
Hallo, vielen Dank für die Antwort. In der Funktion searchfilter ist die variable $sortby bereits definiert.
Ich habe es eingefügt. Doch leider geht es nicht. Ich schätze mal, dass ich hier etwas falsch mache. Hier die ganze Datei. Vielleicht
könntest Du noch einmal so freundlich sein und mir bitte helfen.
index.php
getdata1.php
Pagination.class.php
Ich habe es eingefügt. Doch leider geht es nicht. Ich schätze mal, dass ich hier etwas falsch mache. Hier die ganze Datei. Vielleicht
könntest Du noch einmal so freundlich sein und mir bitte helfen.
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body link="white" vlink="white" alink="white">
<script>
// Show loading overlay when ajax request starts
$( document ).ajaxStart(function() {
$('.loading-overlay').show();
});
// Hide loading overlay when ajax request completes
$( document ).ajaxStop(function() {
$('.loading-overlay').hide();
});
</script>
<script>
function searchFilter(page_num) {
page_num = page_num?page_num:0;
var keywords = $('#keywords').val();
var sortBy = $('#sortBy').val();
$.ajax({
type: 'POST',
url: 'getData1.php',
data:'page='+page_num+'&keywords='+keywords+'&sortBy='+sortBy,
beforeSend: function () {
$('.loading-overlay').show();
},
success: function (html) {
$('#postContent').html(html);
$('.loading-overlay').fadeOut("slow");
}
});
}
</script>
<div class="post-search-panel">
<input type="text" id="keywords" placeholder="Suche..." onkeyup="searchFilter();"/>
<input id="reload" type="button" value="Neue Suche" onclick="javascript:location.reload();" />
<select id="sortBy" onchange="searchFilter();">
<option value="">Nach Datum sortieren</option>
<option value="asc">Aufsteigend</option>
<option value="desc">Absteigend</option>
</select>
</div>
<div class="post-wrapper">
<!-- Loading overlay -->
<div class="loading-overlay"><div class="overlay-content"><font color="white" size="1">Suche Einträge...</font></div></div>
<!-- Post list container -->
<div id="postContent">
<?php
// Include pagination library file
include_once 'Pagination.class.php';
// Include database configuration file
require_once 'dbConfig.php';
// Set some useful configuration
$baseURL = 'getData1.php';
$limit = 10;
// Count of all records
$query = $db->query("SELECT COUNT(*) as rowNum
FROM eingabeform_event");
$result = $query->fetch_assoc();
$rowCount= $result['rowNum'];
// Initialize pagination class
$pagConfig = array(
'baseURL' => $baseURL,
'totalRows' => $rowCount,
'perPage' => $limit,
'contentDiv' => 'postContent',
'link_func' => 'searchFilter'
);
$pagination = new Pagination($pagConfig);
// Fetch records based on the limit
$query = $db->query("SELECT id, Veranstalter, Strasse,
Stadt, Telefon, Email, Genre, Band, Titel,DATE_FORMAT(Datum, '%d.%m.%Y') AS Datum,
Uhrzeit, Preis, Veranstaltungsort, ArtV, AdresseV, StadtV, BundeslandV, LandV, LinkV,
Nachricht
FROM eingabeform_event ORDER BY Datum $sortby LIMIT $limit");
if($query->num_rows > 0){
?>
<hr>
<?php
echo "<center>";
echo "<table border=\"1\">\n";
echo "<tr align left>";
echo "<th width=120><font face=arial color=#FFFFFF>Datum</font></th>";
echo "</tr>";
echo "</table>";
echo "<center>";
?>
<!-- Display posts list -->
<div class="post-list">
<?php while($row = $query->fetch_assoc()){ ?>
<div class="list-item"><a href="#">
<?php
echo "<center>";
echo "<table border=\"1\">\n";
echo "<tr align=left>";
echo "<td width=120><font face=arial color=#FFFFFF size=2>" . $row["Datum"] . "</font></td>";
echo "</tr>";
echo "</table>";
echo "<center>";
?></a></div>
<?php } ?>
</div>
<hr>
<div class="outline_2">
<div class="menu"><?php echo $pagination->createLinks(); ?>
</div>
<?php
}else{
echo '<p>Keine Veranstaltungen gefunden...</p>';
}
?>
</div>
</div>
</div>
</body>
</html>
getdata1.php
<?php
if(isset($_POST['page'])){
// Include pagination library file
include_once 'Pagination.class.php';
// Include database configuration file
require_once 'dbConfig.php';
// Set some useful configuration
$baseURL = 'getData1.php';
$offset = !empty($_POST['page'])?$_POST['page']:0;
$limit = 10;
// Set conditions for search
if (preg_match("/^(0[1-9]|1[0-2])\.(0[1-9]|[1-2][0-9]|3[0-1])\.([0-9]{4})$/",$date)) {
// Suche nach Datum
} else {
// Suche nach Text
}
$whereSQL = $orderSQL = '';
if(!empty($_POST['keywords'])){
$whereSQL = "WHERE Datum LIKE '%".$_POST['keywords']."%' OR Band LIKE '%".$_POST['keywords']."%' OR Genre LIKE '%".$_POST['keywords']."%' OR StadtV LIKE '%".$_POST['keywords']."%' OR BundeslandV LIKE '%".$_POST['keywords']."%'
OR LandV LIKE '%".$_POST['keywords']."%'";
}
if(!empty($_POST['sortBy'])){
$orderSQL = " ORDER BY Datum ".$_POST['sortBy'];
}else{
$orderSQL = " ORDER BY Datum ASC ";
}
// Count of all records
$query = $db->query("SELECT COUNT(*) as rowNum FROM eingabeform_event ".$whereSQL.$orderSQL);
$result = $query->fetch_assoc();
$rowCount= $result['rowNum'];
$pagConfig = array(
'baseURL' => $baseURL,
'totalRows' => $rowCount,
'perPage' => $limit,
'currentPage' => $offset,
'contentDiv' => 'postContent',
'link_func' => 'searchFilter'
);
$pagination = new Pagination($pagConfig);
// Fetch records based on the offset and limit
$query = $db->query("SELECT id, Veranstalter, Strasse,
Stadt, Telefon, Email, Genre, Band, Titel,DATE_FORMAT(Datum, '%d.%m.%Y') AS Datum,
Uhrzeit, Preis, Veranstaltungsort, ArtV, AdresseV, StadtV, BundeslandV, LandV, LinkV,
Nachricht
FROM eingabeform_event $sortby $whereSQL $orderSQL LIMIT $offset,$limit");
if($query->num_rows > 0){
?>
<?php $Datum = setlocale(LC_TIME, 'de_DE.UTF8'); {
echo "<font face=\"arial\" size=1 color=#66CCFF><p>Abgefragt am: <b>".date('d.m.Y H:i').' Uhr'."</b></p>";
}
?>
<hr>
<?php
echo "<center>";
echo "<table border=\"1\">\n";
echo "<tr align left>";
echo "<th width=120><font face=arial color=#FFFFFF size=3>Datum</font></th>";
echo "<th width=150><font face=arial color=#FFFFFF size=3>Stadt</font></th>";
echo "<th width=150><font face=arial color=#FFFFFF size=3>Bundesland</font></th>";
echo "<th width=150><font face=arial color=#FFFFFF size=3>Land</font></th>";
echo "<th width=100><font face=arial color=#FFFFFF size=3>Genre</font></th>";
echo "<th width=150><font face=arial color=#FFFFFF size=3>Band</font></th>";
echo "<th width=120><font face=arial color=#FFFFFF size=3>ArtV</font></th>";
echo "<th width=150><font face=arial color=#FFFFFF size=3>Veranstaltungsort</font></th>";
echo "<th width=80><font face=arial color=#FFFFFF size=3>Uhrzeit</font></th>";
echo "<th width=60><font face=arial color=#FFFFFF size=3>Link</font></th>";
echo "</tr>";
echo "</table>";
echo "<center>";
?>
<!-- Display posts list -->
<div class="post-list">
<?php while($row = $query->fetch_assoc()){ ?>
<div class="list-item"><a href="#">
<?php
echo "<center>";
echo "<table border=\"1\">\n";
echo "<tr align=left>";
echo "<td width=120><font face=arial color=#FFFFFF size=2>" . $row["Datum"] . "</font></td>";
echo "<td width=150><font face=arial color=#FFFFFF size=2>" . $row["StadtV"] . "</font></td>";
echo "<td width=150><font face=arial color=#FFFFFF size=2>" . $row["BundeslandV"] . "</font></td>";
echo "<td width=150><font face=arial color=#FFFFFF size=2>" . $row["LandV"] . "</font></td>";
echo "<td width=100><font face=arial color=#FFFFFF size=2>" . $row["Genre"] . "</font></td>";
echo "<td width=150><font face=arial color=#FFFFFF size=2>" . $row["Band"] . "</font></td>";
echo "<td width=120><font face=arial color=#FFFFFF size=2>" . $row["ArtV"] . "</font></td>";
echo "<td width=150><font face=arial color=#FFFFFF size=2>" . $row["Veranstaltungsort"] . "</font></td>";
echo "<td width=80><font face=arial color=#FFFFFF size=2>" . $row["Uhrzeit"] . "</font></td>";
echo "<td width=60><a href=" . $row["LinkV"] . ">INFO</a></td>";
echo "</tr>";
echo "</table>";
echo "<center>";
?></a></div>
<?php } ?>
</div>
<hr>
<!-- Display pagination links -->
<?php echo $pagination->createLinks(); ?>
<?php
}else{
echo '<p>Keine Einträge vorhanden</p>';
}
}
?>
<?php
class Pagination{
var $baseURL = '';
var $totalRows = '';
var $perPage = 10;
var $numLinks = 3;
var $currentPage = 0;
var $firstLink = '‹ First';
var $nextLink = '>';
var $prevLink = '<';
var $lastLink = 'Last ›';
var $fullTagOpen = '<div class="pagination">';
var $fullTagClose = '</div>';
var $firstTagOpen = '';
var $firstTagClose = ' ';
var $lastTagOpen = ' ';
var $lastTagClose = '';
var $curTagOpen = ' <b>';
var $curTagClose = '</b>';
var $nextTagOpen = ' ';
var $nextTagClose = ' ';
var $prevTagOpen = ' ';
var $prevTagClose = '';
var $numTagOpen = ' ';
var $numTagClose = '';
var $anchorClass = '';
var $showCount = true;
var $currentOffset = 0;
var $contentDiv = '';
var $additionalParam= '';
var $link_func = '';
function __construct($params = array()){
if (count($params) > 0){
$this->initialize($params);
}
if ($this->anchorClass != ''){
$this->anchorClass = 'class="'.$this->anchorClass.'" ';
}
}
function initialize($params = array()){
if (count($params) > 0){
foreach ($params as $key => $val){
if (isset($this->$key)){
$this->$key = $val;
}
}
}
}
/**
* Generate the pagination links
*/
function createLinks(){
// If total number of rows is zero, do not need to continue
if ($this->totalRows == 0 OR $this->perPage == 0){
return '';
}
// Calculate the total number of pages
$numPages = ceil($this->totalRows / $this->perPage);
// Is there only one page? will not need to continue
if ($numPages == 1){
if ($this->showCount){
$info = '<p><font face=arial color=orange size=2>Einträge : ' . $this->totalRows.'</font></p>';
return $info;
}else{
return '';
}
}
// Determine the current page
if ( ! is_numeric($this->currentPage)){
$this->currentPage = 0;
}
// Links content string variable
$output = '';
// Showing links notification
if ($this->showCount){
$currentOffset = $this->currentPage;
$info = '<font face=arial color=orange size=2>Einträge ' . ( $currentOffset + 1 ) . ' bis ' ;
if( ($currentOffset + $this->perPage) < $this->totalRows)
$info .= $currentOffset + $this->perPage;
else
$info .= $this->totalRows;
$info .= ' / ' . $this->totalRows . ' | ';
$output .= $info;
}
$this->numLinks = (int)$this->numLinks;
// Is the page number beyond the result range? the last page will show
if ($this->currentPage > $this->totalRows){
$this->currentPage = ($numPages - 1) * $this->perPage;
}
$uriPageNum = $this->currentPage;
$this->currentPage = floor(($this->currentPage/$this->perPage) + 1);
// Calculate the start and end numbers.
$start = (($this->currentPage - $this->numLinks) > 0) ? $this->currentPage - ($this->numLinks - 1) : 1;
$end = (($this->currentPage + $this->numLinks) < $numPages) ? $this->currentPage + $this->numLinks : $numPages;
// Render the "First" link
if ($this->currentPage > $this->numLinks){
$output .= $this->firstTagOpen
. $this->getAJAXlink( '' , $this->firstLink)
. $this->firstTagClose;
}
// Render the "previous" link
if ($this->currentPage != 1){
$i = $uriPageNum - $this->perPage;
if ($i == 0) $i = '';
$output .= $this->prevTagOpen
. $this->getAJAXlink( $i, $this->prevLink )
. $this->prevTagClose;
}
// Write the digit links
for ($loop = $start -1; $loop <= $end; $loop++){
$i = ($loop * $this->perPage) - $this->perPage;
if ($i >= 0){
if ($this->currentPage == $loop){
$output .= $this->curTagOpen.$loop.$this->curTagClose;
}else{
$n = ($i == 0) ? '' : $i;
$output .= $this->numTagOpen
. $this->getAJAXlink( $n, $loop )
. $this->numTagClose;
}
}
}
// Render the "next" link
if ($this->currentPage < $numPages){
$output .= $this->nextTagOpen
. $this->getAJAXlink( $this->currentPage * $this->perPage , $this->nextLink )
. $this->nextTagClose;
}
// Render the "Last" link
if (($this->currentPage + $this->numLinks) < $numPages){
$i = (($numPages * $this->perPage) - $this->perPage);
$output .= $this->lastTagOpen . $this->getAJAXlink( $i, $this->lastLink ) . $this->lastTagClose;
}
// Remove double slashes
$output = preg_replace("#([^:])//+#", "\\1/", $output);
// Add the wrapper HTML if exists
$output = $this->fullTagOpen.$output.$this->fullTagClose;
return $output;
}
function getAJAXlink( $count, $text) {
if($this->link_func == '' && $this->contentDiv == '')
return '<a href="'.$this->baseURL.'?'.$count.'"'.$this->anchorClass.'>'.$text.'</a>';
$pageCount = $count?$count:0;
if(!empty($this->link_func)){
$linkClick = 'onclick="'.$this->link_func.'('.$pageCount.')"';
}else{
$this->additionalParam = "{'page' : $pageCount}";
$linkClick = "onclick=\"$.post('". $this->baseURL."', ". $this->additionalParam .", function(data){
$('#". $this->contentDiv . "').html(data); }); return false;\"";
}
return "<a href=\"javascript:void(0);\" " . $this->anchorClass . "
". $linkClick .">". $text .'</a>';
}
}
?>
- Copy internal comment link
- Copy external comment link
- To the beginning of the comments
https://administrator.de/forum/input-type-als-text-und-date-format-579843.html#comment-1458957
[content:579843#1458957]
Ein guter Rat:
Nimm dir jemanden der das für dich macht, denn du willst oder kannst das nicht
Nimm dir jemanden der das für dich macht, denn du willst oder kannst das nicht
omroettger Jun 18, 2020 at 05:48:18 (UTC)
- Copy internal comment link
- Copy external comment link
- To the beginning of the comments
https://administrator.de/forum/input-type-als-text-und-date-format-579843.html#comment-1458967
[content:579843#1458967]
Hallo,
ich hatte mich gestern Abend noch mal mit dem Thema auseinander gesetzt und habe in Verbindung mit Deiner Antwort die Lösung gefunden.
Ich gebe Dir absolut recht, ich hätte mich mit Deiner Antwort mehr auseinander setzen müssen, nur laufen bei mir sehr viele Projekte zusammen und dann spielt die Zeit eine Rolle. Aber das ist nicht Euer Problem.
Vielen Dank für Deinen Beitrag und den Hinweis.
ich hatte mich gestern Abend noch mal mit dem Thema auseinander gesetzt und habe in Verbindung mit Deiner Antwort die Lösung gefunden.
Ich gebe Dir absolut recht, ich hätte mich mit Deiner Antwort mehr auseinander setzen müssen, nur laufen bei mir sehr viele Projekte zusammen und dann spielt die Zeit eine Rolle. Aber das ist nicht Euer Problem.
Vielen Dank für Deinen Beitrag und den Hinweis.