Content Management System für das News-Verwaltungssystem
Die Grundanforderung von webbasierten Systemen ist oft identisch: Es müssen (teil-)dynamische HTML-Seiten dargestellt sowie Verbindungen zu einer Datenbank hergestellt werden. Diese grundlegenden Funktionalitäten werden daher in einem Basissystem zusammengefasst, auf das Sie als Programmierer zugreifen können, um schnell und flexibel Inhalt und Logik zu erstellen. Unser Basissystem hat eine festgelegte Ordnerstruktur, die die Übersichtlichkeit eines Projektes während der Implementierung garantieren soll. Dabei werden auf oberster Ebene alle Dateien erstellt, da nicht so viel Dateien für das News-Verwaltungssystem gebraucht werden.labconnect.php
Diese Datei baut die Verbindung mit dem MYSQL-Server auf. Dabei müssen der Hostname, Datenbankname, Benutzername und das Passwort bekannt und richtig angegeben werden. Der Inhalt könnte wie folgt aussehen:<?php mysql_connect("localhost", "your_username", "your_password"); mysql_select_db("your_databasename"); ?>Hinweise: Hostname ist immer localhost. Die Werte für your_username, your_password und your_databasename erhalten Sie von mir, wenn Sie in meinem Kurs eingeschrieben sind. Es ist nicht zulässig, Ihre persönlichen Daten an anderen Personen weiterzugeben.
labheader.php
Diese Datei beinhaltet alle CSS-Dateien, die für das ganze Projekt verwendet werden. Diese wird in jede Hauptdatei eingebunden.<html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta content='text/html; charset=utf-8' http-equiv='Content-Type' /> <title>News by Mehdi Bandegani</title> <link href='css/bootstrap.min.css' rel='stylesheet'> <link href='css/startmin.css' rel='stylesheet'> <link href='css/font-awesome.min.css' rel='stylesheet' type='text/css'> <link rel='stylesheet' href='css/site.css'> <body> <!-- Gesamter Bereich:Anfang von wrapper --> <div id='wrapper'> <!-- Navigationsanfang--> <nav class='navbar navbar-default navbar-fixed-top' role='navigation' style='background-color: #F0F8FF;'> <ul class='nav navbar-nav'> <li><a href='index.php'><span class='fa fa-home'></span> HOME</a></li> <li><a href='labnewsdescription.php'><span class='fa fa-news'></span> DESCRIPTION</a></li> <?php if ($_SESSION['id']>0){ ?> <li><a href='lablogout.php'><span class='mif-user-minus icon'>LOGOUT</span></a></li> <?php } else { ?> <li><a href='lablogin.php'><span class='mif-user-plus icon'>LOGIN</span></a></li> <?php } ?> </ul> </nav>
labfooter.php
Diese Datei enthält alle js-Dateien, die für das Projekt benötigt werden. Diese wird in jede Hauptdatei eingebunden.<!-- ende class='col-lg-12' in labnaveside.php--> </div> </div> </div> <!-- ende id='page-wrapper' in labnaveside.php--> </div> <!-- ende id='wrapper' in labheader.php--> </div> <!-- /#wrapper --> <footer class='page-footer font-small blue-grey lighten-5'> <div class='footer-copyright text-center py-3' style='background-color: #F0F8FF;'> <ul class='list-unstyled'> <br /> <li> <a href='https://www.haw-hamburg.de/startseite.html'>HAW-Hamburg</a> </li> <li> <a href='https://design.haw-hamburg.de/home/das-department-design/'>Departement Design</a> </li> <li> <a href='https://vorlesungsverzeichnis.design.haw-hamburg.de/'>Vorlesungsverzeichnis</a> </li> </ul> <a href='http://www.bandegani.de/'> <span class='fa fa-copyright'></span>2020 Copyright bandegani.de </a> </div> </footer> <script src="js/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/startmin.js"></script> <script> // tooltip demo $('.tooltip-demo').tooltip({ selector: '[data-toggle=tooltip]', container: 'body' }) // popover demo $('[data-toggle=popover]').popover() $('.carousel').carousel() </script> </body> </html>
<div class="navbar-default sidebar" role="navigation" style='background-color: #F0F8FF;'> <div class="sidebar-nav navbar-collapse" style='background-color: #F0F8FF;'> <ul class="nav" id="side-menu"> <li class="sidebar-search"> <div class="input-group custom-search-form"> <input type="text" class="form-control" placeholder="Search..."> <span class="input-group-btn"> <button class="btn btn-primary" type="button"> <i class="fa fa-search"></i> </button> </span> </div> <!-- /input-group --> </li> <?php session_start(); if($_SESSION['id']>=1) { ?> <li> <a href='http://www.bandegani.de/itkurs/labnews/#'>Manage record<span class='fa arrow'></span></a> <ul class='nav nav-second-level'> <li><a href='http://www.bandegani.de/itkurs/labnews/labshownews.php'>Show</a></li> <li><a href='http://www.bandegani.de/itkurs/labnews/labeditnews.php'>Edit</a></li> <li><a href='http://www.bandegani.de/itkurs/labnews/labdeletenews.php'>Delete</a></li> <li><a href='http://www.bandegani.de/itkurs/labnews/labinsertnews.php'>Insert</a></li> <li><a href='http://www.bandegani.de/itkurs/labnews/labsearchnews.php'>Search</a></li> <li><a href='http://www.bandegani.de/itkurs/labnews/labsortnews.php'>Sort</a></li> </ul> </li> <?php } ?> </ul> </div> </div> <div id="page-wrapper"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> <br />
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); ?> <div class='container-fluid'> <div class='row'> <div class='col-lg-12'> <div class='panel panel-default'> <div class='panel-heading'> <b>Dateistruktur des News-Verwaltungssystems</b> </div> <div class='panel-body'> <div class='table-responsive'> <table class="table"> <thead> <tr> <th>Dateiname</th> <th>Beschreibung</th> <th>Abhängigkeiten</th> </tr> </thead> <tbody> <tr> <td>index.php</td> <td>Liste der Dateien</td> <td>labheader.php,labsidenav.php' und labfooter.php</td> </tr> <tr class='info'> <td>labheader.php</td> <td>Menüpunkte</td> <td>Hauptdatei und CSS-Dateien</td> </tr> <tr> <td>labfooter.php</td> <td>Footer Bereich</td> <td>Hauptdatei und JS-Dateien</td> </tr> <tr class='info'> <td>labsidenav.php</td> <td>Linker Navigation-Bereich</td> <td>Hauptdatei</td> </tr> <tr> <td>labnewsdesciption.php</td> <td>Dokumentation für das News-Verwaltungssystem</td> <td>Hauptdatei</td> </tr> <tr class='info'> <td>lablogin.php</td> <td>Benutzeranmeldung</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr> <td>labshownews.php</td> <td>Benutzerabhängige News anzeigen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr class='info'> <td>labinsertnews.php</td> <td>Benutzerabhängige News hinzufügen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr> <td>labeditnews.php</td> <td>Benutzerabhängige News ändern</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr class='info'> <td>labdeletenews.php</td> <td>Benutzerabhängige News löschen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr> <td>labsearchnews.php</td> <td>Benutzerabhängige News suchen</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> <tr class='info'> <td>labsortnews.php</td> <td>Benutzerabhängige News sortieren</td> <td>labheader.php,labsidenav.php',labconnect.php, labfooter.php und MySQL-Datenbank-Server</td> </tr> </tbody> </table> </div></div></div> </div></div></div> <?php include ("labfooter.php"); ?>
Tabellenschema für das Newssystem
Datenbanktabelle lab_tblusers
CREATE TABLE IF NOT EXISTS `lab_tblusers` ( `id` int(11) NOT NULL, `name` varchar(50) DEFAULT NULL, `prename` varchar(50) DEFAULT NULL, `modified` datetime DEFAULT NULL, `email` varchar(100) DEFAULT NULL, `password` varchar(32) DEFAULT NULL ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ALTER TABLE `lab_tblusers` ADD PRIMARY KEY (`id`); ALTER TABLE `lab_tblusers` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
Datenbanktabelle (lab_tblnews)
CREATE TABLE IF NOT EXISTS `lab_tblnews` ( `id` int(11) NOT NULL, `newsdate` date NOT NULL, `idusers` int(11) NOT NULL, `title` varchar(50) NOT NULL, `news` text NOT NULL ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; ALTER TABLE `lab_tblnews` ADD PRIMARY KEY (`id`); ALTER TABLE `lab_tblnews` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;Die Inhalte der Tabelle (lab_tblnews) kann wie folgt aussehen.
Der Inhalt der Datei (lablogin.php)
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include ('labconnect.php'); ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Login - Formular</h2> </div> <div class='panel-body'> <form enctype='multipart/form-data' method='post' action='lablogin.php'> <div class='form-group'> <label class='control-label' for='inputUsername'>Username:</label> <input type='text' name='email' class='form-control' id='inputUsername' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputPassword'>Password:</label> <input type='Password' name='password' class='form-control' id='inputPassword' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Login</button> </div> </form> </div> </div></div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php if(isset($_POST['send'])) { session_start(); $email=$_POST['email']; $password= $_POST['password']; $email=stripcslashes($email); $password= md5($password); $sqlstr = "select * from lab_tblusers where email='$email' AND password='$password'"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_fetch_array($res); if ($num['email']==$email && $num['password']==$password){ $_SESSION['id'] = $num['id']; $_SESSION['email'] = $email; header("Location: index.php"); } else { ?> <div class='row'> <div class='col-md-2 col-sm-4 col-xs-12'></div> <div class='col-md-8 col-sm-4 col-xs-12'> <span class='label label-danger'>You could not be registered. You must be logged in to see this page.!</span> </div> <div class='col-md-8 col-sm-4 col-xs-12'></div> </div> <?php } mysql_free_result($res); } include("labfooter.php"); ?>
Soll sich die angemeldete Person am System abmelden, ist die Datei (lablogout.php) vorgesehen.
Der Inhalt der Datei (lablogout.php)
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include ('labconnect.php'); session_destroy(); ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-success'>You are Logout!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <hr> <?php header('location:index.php'); include("labfooter.php"); ?>
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); if($_SESSION['id']<=0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>You are not logged in!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { $id=$_SESSION['id']; $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers=lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY id " . "ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-4 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-default'> <div class='panel-heading'> <b>Show news</b> </div> <div class='panel-body'> <div class='table-responsive'> <table class='table table-hover'> <thead> <tr> <th><b>Id</b></th><th><b>Email</h></td> <th><b>Datum</b></th> <th><b>Titel</b></th><th><b>Beitrag</b></th> </tr> </thead> <tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> </div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } } include("labfooter.php"); ?>
News-Daten anzeigen mit der Datei labshownews.php
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);Gesamter Inhalt der Datei labinsertnews.php
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); if($_SESSION['id']<=0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>You are not logged in!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { if(isset($_POST['send'])) { $id=$_SESSION['id']; $newsdate=date('Y-m-d', strtotime($_POST['newsdate'])); $title = $_POST['title']; $news = $_POST['news']; $sqlstr = "insert lab_tblnews (newsdate, idusers, title, news) values ('$newsdate', '$id', '$title', '$news')"; $res = mysql_query($sqlstr) or die ("keine Verbindung mit der Datenbank ".mysql_error()); $num = mysql_affected_rows(); if ($num>0) { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <span class='label label-success'>The record has been added!</span> </div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <span class='label label-danger'>The record was not added!</span> </div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php } mysql_free_result($res); }else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Insert - News</h2> </div> <div class='panel-body'> <form class='lab_formbox lab_formstyle' action='labinsertnews.php' method='post'> <div class='form-group'> <label class='control-label' for='inputNewsdate'>Newsdate:</label> <input type='text' name='newsdate' class='form-control' id='inputNewsdate' placeholder='TT.MM.JJJJ'> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputTitle'>Title:</label> <input type='text' name='title' class='form-control' id='inputTitle' placeholder='Enter title'> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputNews'>News:</label> <textarea name='news' class='form-control' id='inputNews' placeholder='Enter a larg string'></textarea> <div style='height: 15px;'></div> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Send</button> </div> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php } } include("labfooter.php"); ?>
Das Formular für das Hinzufügen der News-Daten
News-Daten nach dem Hinzufügen
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;Gesamter Inhalt der Datei labeditnews.php
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); if($_SESSION['id']<=0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>You are not logged in!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { $id = $_SESSION['id']; if (isset($_POST["auswahl"])) { $sqlstr = "select * from lab_tblnews WHERE id = ". $_POST['auswahl'] ; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $dsatz = mysql_fetch_array($res); ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit - News</h2> </div> <div class='panel-body'> <form class='lab_formbox lab_formstyle' action='labeditnews.php' method='post'> <div class='form-group'> <label class='control-label' for='inputId'>Id:</label> <input type='text' name='id' value = '<?php echo $_POST["auswahl"]; ?>' class='form-control' id='inputid' disabled> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputNewsdate'>Newsdate:</label> <input type='text' name='newsdate' value = '<?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?>' class='form-control' id='inputNewsdate' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputTitle'>Title:</label> <input type='text' name='title' value = '<?php echo $dsatz["title"]; ?>' class='form-control' id='inputTitle' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputNews'>News:</label> <textarea name='news' class='form-control' id='inputNews' required><?php echo $dsatz["news"]; ?></textarea> <div style='height: 15px;'></div> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Send</button> </div> <input type='hidden' name='selected' value = '<?php echo $_POST["auswahl"]; ?>' /> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } if (isset($_POST["send"])) { $newsdate=date('Y-m-d', strtotime($_POST['newsdate'])); $sqlstr = "update lab_tblnews set" . " newsdate = '" . $newsdate . "'," . " title = '" . $_POST["title"] . "'," . " news = '" . $_POST["news"] . "'" . " where id = " . $_POST["selected"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0){ ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>The record was not changed!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } mysql_free_result($res); } $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers= lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY id " . "ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Edit - News</h2> </div> <div class='panel-body'> <p align='center'><b>Wählen Sie aus, welcher Datensatz geändert werden soll?</b> <form action='labeditnews.php' method='post'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> <th>Auswahl</th></b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> <td><input type='checkbox' name='auswahl' value='<?php echo $dsatz["id"]; ?>' /></td> </tr> <?php } ?> </tbody></table> <label></label><input type='submit' value='Show record' /> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } include("labfooter.php"); ?>Wenn der Eintrag mit der Nummer 47 geändert werden soll, sollen die 3 Abbildungen unten die Änderung veranschaulichen.
Das Formular für das Ändern der News-Daten
Das Formular zum Ändern der News-Daten
News-Daten nach dem Ändern
DELETE FROM table_name WHERE condition;Gesamter Inhalt der Datei labdeletenews.php
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); if($_SESSION['id']<=0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>You are not logged in!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { $id = $_SESSION['id']; if (isset($_POST["auswahl"])) { $sqlstr = "select * from lab_tblnews WHERE id = ". $_POST['auswahl'] ; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $dsatz = mysql_fetch_array($res); ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>DELETE - News</h2> </div> <div class='panel-body'> <form class='lab_formbox lab_formstyle' action='labdeletenews.php' method='post'> <div class='form-group'> <label class='control-label' for='inputId'>Id:</label> <input type='text' name='id' value = '<?php echo $_POST["auswahl"]; ?>' class='form-control' id='inputid' disabled> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputNewsdate'>Newsdate:</label> <input type='text' name='newsdate' value = '<?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?>' class='form-control' id='inputNewsdate' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputTitle'>Title:</label> <input type='text' name='title' value = '<?php echo $dsatz["title"]; ?>' class='form-control' id='inputTitle' required> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputNews'>News:</label> <textarea name='news' class='form-control' id='inputNews' required><?php echo $dsatz["news"]; ?></textarea> <div style='height: 15px;'></div> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Send</button> </div> <input type='hidden' name='selected' value = '<?php echo $_POST["auswahl"]; ?>' /> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } if (isset($_POST["send"])) { $newsdate=date('Y-m-d', strtotime($_POST['newsdate'])); $sqlstr = "DELETE FROM lab_tblnews where id = " . $_POST["selected"]; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_affected_rows(); if ($num<=0){ ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>The record was not changed!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } mysql_free_result($res); } $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers= lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY id " . "ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>DELETE - News</h2> </div> <div class='panel-body'> <p align='center'><b>Wählen Sie aus, welcher Datensatz gelöscht werden soll?</b> <form action='labdeletenews.php' method='post'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> <th>Auswahl</th></b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> <td><input type='checkbox' name='auswahl' value='<?php echo $dsatz["id"]; ?>' /></td> </tr> <?php } ?> </tbody></table> <label></label><input type='submit' value='Show record' /> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } include("labfooter.php"); ?>Wenn der Eintrag mit der Nummer 47 gelöscht werden soll, sollen die 3 Abbildungen unten die Löschung veranschaulichen.
Das Formular für das Löschen der News-Daten
Das Formular zum Löschen der News-Daten
News-Daten nach dem Löschen
SELECT * FROM table_name WHERE field_name LIKE 'placeholder';Gesamter Inhalt der Datei labsearchnews.php
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); if($_SESSION['id']<=0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>You are not logged in!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { $id = $_SESSION['id']; $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers= lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY id " . "ASC"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php } mysql_free_result($res); ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Search - News</h2> </div> <div class='panel-body'> <form class='lab_formbox lab_formstyle' action='labsearchnews.php' method='post'> <div class='form-group'> <label class='control-label' for='inputVon'>Von:</label> <input type='text' name='von' class='form-control' id='inputVon' placeholder='enter id'> <div style='height: 15px;'></div> </div> <div class='form-group'> <label class='control-label' for='inputBis'>Bis:</label> <input type='text' name='bis' class='form-control' id='inputBis' placeholder='enter id'> <div style='height: 15px;'></div> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Send</button> </div> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php if(isset($_POST['send'])){ $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers=lab_tblusers.id WHERE lab_tblnews.idusers='$id' AND lab_tblnews.id >= " . $_POST["von"] . " AND lab_tblnews.id <= " . $_POST["bis"]; $sqlstr .= " ORDER BY lab_tblnews.id"; $res = mysql_query($sqlstr) or die ("no connection to the database ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } } } include("labfooter.php"); ?>
Die Liste der News-Daten
Wenn z.B. die Einträge bei dem Feld id von 3 bis 10 gesucht bzw. gefiltert und angezeigt werden sollen, sollen die 2 Abbildungen unten diese veranschaulichen.Das Formular zum Suchen bestimmter News-Daten
News-Daten nach dem Suchen
SELECT * FROM tablle_name ORDER BY field_name;Gesamter Inhalt der Datei labsortnews.php
<?php session_start(); include("labheader.php"); include('labsidenav.php'); include('labconnect.php'); if($_SESSION['id']<=0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>You are not logged in!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { $id = $_SESSION['id']; $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers=lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY newsdate " . "DESC"; $res = mysql_query($sqlstr) or die ("keine Verbindung mit der Datenbank ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Search - News</h2> </div> <div class='panel-body'> <form class='lab_formbox lab_formstyle' action='labsortnews.php' method='post'> <div class='form-group'> <label class='control-label' for='inputVon'>Sortiere nach:</label> <select name='sort' class='form-control'> <option value='id'>Id-Nummer</option> <option value='newsdate'>Datum</option> <option value='title'>Titel</option> <option value='news'>Beitrag</option> </select> </div> <div class='form-group'> <button type='submit' name='send' class='btn btn-primary'> <span class='fa fa-lock'></span> Send</button> </div> </form> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php if(isset($_POST['send'])){ // Sortiere nach ID if($_POST["sort"]=="id"){ $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers=lab_tblusers.id WHERE lab_tblnews.idusers='$id' AND lab_tblnews.id <= lab_tblnews.id ORDER BY lab_tblnews.id"; $res = mysql_query($sqlstr) or die ("keine Verbindung mit der Datenbank ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } // end of sort=id } // Sortiere nach Datum If($_POST["sort"]=="newsdate"){ $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email"; $sqlstr .= " from lab_tblnews"; $sqlstr .= " INNER JOIN lab_tblusers"; $sqlstr .= " ON lab_tblnews.idusers=lab_tblusers.id"; $sqlstr .= " WHERE lab_tblnews.idusers='$id'"; #$sqlstr .= " AND lab_tblnews.id <= lab_tblnews.id"; $sqlstr .= " ORDER BY lab_tblnews.newsdate"; $res = mysql_query($sqlstr) or die ("keine Verbindung mit der Datenbank ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } // end of sort=newsdate } // Sortiere nach Titel If($_POST["sort"]=="title"){ $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers=lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY lab_tblnews.title"; $res = mysql_query($sqlstr) or die ("keine Verbindung mit der Datenbank ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } // end of sort=title } // Sortiere nach Beitrag If($_POST["sort"]=="news"){ $sqlstr = "select lab_tblnews.id, lab_tblnews.newsdate, lab_tblnews.idusers, lab_tblnews.title, lab_tblnews.news, lab_tblusers.email from lab_tblnews INNER JOIN lab_tblusers ON lab_tblnews.idusers=lab_tblusers.id WHERE lab_tblnews.idusers='$id' ORDER BY lab_tblnews.news"; $res = mysql_query($sqlstr) or die ("keine Verbindung mit der Datenbank ".mysql_error()); $num = mysql_num_rows($res); if ($num == 0) { ?> <div class='row'> <div class='col-md-2 col-sm-12 col-xs-12'></div> <div class='col-md-8 col-sm-12 col-xs-12'> <span class='label label-danger'>There is no entry!</span> </div> <div class='col-md-2 col-sm-12 col-xs-12'></div> </div> <?php } else { ?> <div class='row'> <div class='col-md-1 col-sm-12 col-xs-12'></div> <div class='col-md-10 col-sm-12 col-xs-12'> <div class='panel panel-primary'> <div class='panel-heading'> <h2 class='panel-title'>Show - News</h2> </div> <div class='panel-body'> <table class='table table-hover'><thead> <tr><b><th>ID</th> <th>Email</th> <th>Datum</th> <th>Titel</th> <th>Beitrag</th> </b></tr> </thead><tbody> <?php while ($dsatz = mysql_fetch_assoc($res)) { ?> <tr> <td><?php echo $dsatz["id"]; ?></td> <td><?php echo $dsatz["email"]; ?></td> <td><?php echo date('d.m.Y', strtotime($dsatz["newsdate"])); ?></td> <td><?php echo $dsatz["title"]; ?></td> <td><?php echo $dsatz["news"]; ?></td> </tr> <?php } ?> </tbody></table> </div></div></div> <div class='col-md-1 col-sm-12 col-xs-12'></div> </div> <?php mysql_free_result($res); } //End of sort=news } // End of send } // End of user } include("labfooter.php"); ?>
Die Liste der News-Daten
Wenn z.B. die Einträge bei dem Feld id sortiert und angezeigt werden sollen, sollen die 2 Abbildungen unten diese veranschaulichen.Das Formular zum Sortieren der News-Daten beim Feld id
News-Daten nach dem Sortieren