Hi
ich hab nachwievor Probleme mit meinem MySQL bzw PHP Script. Ich hab jetzt eine Spalte vom Typ Datetime. Und ich schreibe die Zeit bzw das Datum nach yyyy-mm-dd hh:mm:ss hinein. Und hab ORDER BY zeit (so heißt die Spalte) gemacht allerdings ordnet er nicht richtig, nur nach dem datum und nicht der Zeit.
Und wie forme ich die das Datum in dd.mm.yyyy um? Ich habs allein nicht geschafft. :-(
Ich wäre sehr dankbar für Hilfe.
gruß der bär
Quelltext:
<?
include("var.inc.php"); <- nur server und passwort
//Connection
$connect = @mysql_connect("$db_server","$db_user","$db_pass");
mysql_select_db("$db_select");
if(!$name=="" and !$mail=="" and !$herkunft=="" and !$icq=="" and !$text=="" and $hidden=="hidden")
{
$time = gmstrftime ("%Y-%m-%d %H:%M:%S", time());
$insert = "INSERT INTO posts (name, mail, icq, herkunft, text, zeit) VALUES ('$name', '$mail', '$icq', '$herkunft', '$text', '$time')";
$mysql_ok = mysql_query($insert);
header("Location:show.php");
}
else
{
if($hidden=="hidden")
{
if($name=="")
{
echo "Bitte geben Sie ihren Namen ein!<br>";
}
if($mail=="")
{
echo "Bitte geben Sie ihre Email Adresse ein!<br>";
}
if($herkunft=="")
{
echo "Bitte geben Sie ihre Herkunft ein!<br>";
}
if($text=="")
{
echo "Bitte geben Sie einen Text ein!<br>";
}
}
}
?>
<html>
<body>
<p align="center"><strong><font face="Arial, Helvetica, sans-serif">Gästebuch
von</font></strong> <br>
Es haben sich bereits
<?
$result = mysql_query("SELECT * FROM posts");
$menge = mysql_num_rows($result);
echo $menge;
?>
Besucher eingetragen!
</p>
<form name="form1" method="post" action="">
<input name="hidden" type="hidden" id="hidden" value="hidden">
<table width="394" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="150"><div align="right">Name:</div></td>
<td width="150"> <input name="name" type="text" id="name"> </td>
<td width="150"><div align="right">Email:</div></td>
<td width="150"><input name="mail" type="text" id="mail"></td>
</tr>
<tr>
<td><div align="right">Herkunft:</div></td>
<td><input name="herkunft" type="text" id="herkunft"></td>
<td><div align="right">Icq:</div></td>
<td><input name="icq" type="text" id="icq"></td>
</tr>
<tr>
<td colspan="2"> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="4"><div align="center">
<textarea name="text" cols="50" rows="7" id="text"></textarea>
</div></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4"><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<?
//SELECT
$abfrage = "SELECT * FROM posts ORDER BY zeit('%H%i%S')";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))
{ ?>
<tr>
<td><? echo $row->id ?>.) <b><? echo $row->name ?></b> aus <? echo $row->herkunft ?> schrieb am <? echo $row->datum ?> um <? echo $row->zeit ?> Uhr</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><? echo $row->text ?></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><a href="mailto:<? echo $row->mail ?>"><? echo $row->mail ?></a> - ICQ:<? echo $row->icq ?></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<tr>
<td><b>Kommentar:<b><br><? echo $row->kommentar ?></td>
</tr>
<tr>
<tr>
<td>
<hr>
</td>
</tr>
<?
};
//FREE
$free = mysql_free_result($ergebnis);
$free_ex = @mysql_query($free);
//CONN CLOSE
$db_close = @MYSQL_CLOSE($connect);
?>
</table>
</body>
</html>