Click to See Complete Forum and Search --> : date in french format...


Ness_du_Frat
04-14-2005, 11:45 AM
Hi everybody !!!
I'm following a tutorial on how to write a guestbook, and I have two questions...
First : I don't like the US time format, like : year, month, day. In french, it's day, month, year, and I'm afraid the users will get confused with a US format...
I thought about using the timestamp sthing, but as I don't master php well, I didn't get any result...

Second : I'd like to have the messages on different pages, let's say, 20 messages per page, not more... how can I do that ? I thing, counting the message number, and then, making a function which would print only 20 per page ?

Third ( and last ) : I'd like the "merci de votre message" ( basically thanking the user for writing a message ) to be written below the form, and still being able to see the rest of the messages...

I know I'm asking for a lot of things, sorry... I think it's quite basic, but I'm a newbie, so...

Here, I put the code :
sign.php

<?php
// ======================================================
// PHP GUESTBOOK TUTORIAL PART I
// Tutorial files taken from http://www.daydreamgraphics.com/
// Only for illustration purposes, use as your own risk.
// Not for resale, profit-making, or distributed in anyway. Personal usage only.
// Copyrighted by Magdeline Ng, of http://www.daydreamgraphics.com/
// ======================================================

// view.php

// SQL database Variables
$hostname="sql.free.fr"; //of course, I changed those to mine...
$user="myusername";
$pass="mypassword";
$dbase="mydatabasename";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);

?>
<!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>Livre de Platine</title>
</head>

<body>
<form action="form.php" method="post">
<table width=100% border=0>
<tr>
<td>Nom : </td>
<td><input type="text" name="name" size=15></td>
</tr>
<tr>
<td>Email : </td>
<td><input type="text" name="email" size=15></td>
</tr>
<tr>
<td>Nom du Site : </td>
<td><input type="text" name="sitename" size=15></td>
</tr>
<tr>
<td>URL du Site :</td>
<td><input type="text" name="siteurl" size=15></td>
</tr>
<tr>
<td>Commentaires :</td>
<td><textarea name="comments" cols=30 rows=5></textarea></td>

</tr>
<tr>
<td colspan=2><input type="submit" name="Et hop !" value="Sign">
<input type="reset" name="Tout effacer !" value="Reset">
</td>
</tr></table>
</form>

<?php
// View Guestbook

$q="SELECT * from guestbookn order by date desc";

$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$sitename=$row["sitename"];
$siteurl=$row["siteurl"];
$date=$row["date"];
$comments=$row["comments"];


echo "<p><b>Nom :</b> $name<br>";
echo "<b>Email :</b> $email<br>";
echo "<b>Site :</b> <a href=\"$siteurl\">$sitename</a><br>";
echo "<b>Date :</b> $date<br>";
echo "<b>Commentaires :</b><br> $comments<br></p>";
}
?>



</body>
</html>


sign.php

<?php
// ======================================================
// PHP GUESTBOOK TUTORIAL PART I
// Tutorial files taken from http://www.daydreamgraphics.com/
// Only for illustration purposes, use as your own risk.
// Not for resale, profit-making, or distributed in anyway. Personal usage only.
// Copyrighted by Magdeline Ng, of http://www.daydreamgraphics.com/
// ======================================================


// SQL database Variables

$hostname="sql.free.fr";
$user="username";
$pass="psswd";
$dbase="dbname";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);

// for register globals off
$name = mysql_escape_string($_POST['name']);
$email = mysql_escape_string($_POST['email']);
$sitename = mysql_escape_string($_POST['sitename']);
$siteurl = mysql_escape_string($_POST['siteurl']);
$comments = mysql_escape_string(strip_tags($_POST['comments']));
$ip = $_SERVER['REMOTE_ADDR'];

if (empty($name) || empty($comments))
{
die ('On dirait que vous étiez trop pressé...');
}


// This is form.php
$q="INSERT into guestbookn (id,name,email,sitename,siteurl,date,ip,comments)
VALUES ('','$name','$email','$sitename','$siteurl',now(),'$ip','$comments')";

$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());

if ($result)
{
echo "<p>Merci, $name. L'entrée a été enregistrée !</p>";
}

?>
<html>
<head>
<title>Entr&eacute;e Enregistr&eacute;e ! </title>
</head>
<body>
<p><a href="sign.php" target="_self">Retour au livre de platine</a></p>
</body></html>




This tutorial is cool, but I'd like to improve the guestbook a bit...
Thanks for your help !!! ( in the meantime, I'll keep on searching, maybe I come up with a solution for some of my problems... )
Thanks !!
Ness

96turnerri
04-14-2005, 12:58 PM
Answer #1: date("d/m/y");
Answer #2: SELECT * FROM tablename LIMIT 20 would show 20 posts SELECT * FROM tablename LIMIT, 20, 20 would show 20 posts starting at 20.
Answer #3: jsut after the add form put merci de votre message or thanking you for your message for the non french speaking community

Ness_du_Frat
04-14-2005, 01:15 PM
Answer #1: date("d/m/y");

I did exactly that, and it didn't work... It gave me a crazy date, like 2014-20-04...


Answer #2: SELECT * FROM tablename LIMIT 20 would show 20 posts SELECT * FROM tablename LIMIT, 20, 20 would show 20 posts starting at 20

But if I put this, I will have only 20 posts showing up.. how do I organize them in pages ?

Answer #3: jsut after the add form put merci de votre message or thanking you for your message for the non french speaking community

Mmm... Not sure if I understand well what you mean. I don't want a static : thank you for your message... I want that when the user clicks the submit button, it refreshes the page with the guestbook ( so that he can see his entry ) and writes "thank you for your message" just below the form, on anywhwere on the page...
My main point is not to have an additional page, but to have everything on one page. I'm sure this is the easiest thing on earth, but I really suck in php... :(

But thanks for your suggestions !!! I'll try to go in the answer 2 (SELECT * FROM tablename LIMIT 20 would show 20 posts SELECT * FROM tablename LIMIT, 20 ) dire^ction...

96turnerri
04-14-2005, 01:53 PM
Answer #3 just below the end form tag put
<?php
if ($result) {
echo "Meri de votre message";
}
?>

#1
date("d/m/y") would never return Japanese style dates, you must have done something wrong along the way, do you have a link as an example? also try checking your database setup of that field

#2
to get number of pages and posts
<?php
$sql = "SELECT id FROM guestbookn";
$result = mysql_query($sql) or die(mysql_error());
$posts = mysql_num_rows($result);
$pages = ceil($posts/20);
?>
list page numbers
<?php
for($x=0;$x<=$pages;$x) {
echo "<a href=\"?page=".$x.">".$x."</a> ";
}
?>
alter select statement
<?php
$sql = "SELECT * from guestbookn order by date desc LIMIT 20, ".($_GET["page"] == "" ? "0":$_GET["page"]*20)
?>

Ness_du_Frat
04-14-2005, 02:35 PM
OMG, something terrible happened... lol !!!
I put the code you gave me, and as I opened the browser window, I got something like a billion 0 ( underlined... links ). I guess something went wrong...

For the date thing, I tried it, but I'm sure I must have made a mistake somewhere. The problem is, that the date is defined as a date ( obviously ) in MySQL, and the format is 0000-00-00... I tried defining it as an integer, and getting the date in the right format, and putting it in the database, but... no. didn't work...

As for the "thank you thing", it's still not what I'm looking for. To be more precise, I don't care about this thank you thing. The most important is, not to be redirected to another page... I just want the page to be refreshed....
If you want, you can test it to see what I mean ( it's ugly as hell, just the squeleton for the moment. No css... )
the GB (http://enfantsdelo.free.fr/guestbook/sign.php)
I need to put it back to normal first, that means, without the billion blue zeros... lol !!!

96turnerri
04-14-2005, 05:42 PM
everything looks ok to me apart from you may want to add stripslashes() to your names and descriptions etc set that date up as 00-00-0000

Ness_du_Frat
04-15-2005, 03:09 AM
Ok, sorry I didn't post here before, but I solved all my problems, including the date problem. Now I have the pages, and the french date !
The only thing that remains, is that I don't want to be redirected to another page to say thank you, and that I'd rather that everything styed on the same page...
Is there anything like target=_self ?

96turnerri
04-15-2005, 05:27 PM
like target=_self in waht respect, how are you trying to use it

Ness_du_Frat
04-16-2005, 02:59 AM
like when the user posts a message, I want him to be redirected immediately to the guestbook.
And if I can add a thank you somewhere, it's cool, but not absolutely necessary...

bokeh
04-16-2005, 07:46 AM
Just out of interest when I was doing the date in spanish I could not get php's built in functions make the date look how I wanted it so I did it like this:


<div id="date">
<?php

$day = date ('w');
if ($day == '0') {
$day = 'Domingo';
}elseif ($day == '1') {
$day = 'Lunes';
}elseif ($day == '2') {
$day = 'Martes';
}elseif ($day == '3') {
$day = 'Miercoles';
}elseif ($day == '4') {
$day = 'Jueves';
}elseif ($day == '5') {
$day = 'Viernes';
}elseif ($day == '6') {
$day = 'Sábado';
}

$date = date ('j');

$month = date ('n');
if ($month == '1') {
$month = 'de enero de';
}elseif ($month == '2') {
$month = 'de febrero de';
}elseif ($month == '3') {
$month = 'de marzo de';
}elseif ($month == '4') {
$month = 'de abril de';
}elseif ($month == '5') {
$month = 'de mayo de';
}elseif ($month == '6') {
$month = 'de junio de';
}elseif ($month == '7') {
$month = 'de julio de';
}elseif ($month == '8') {
$month = 'de agosto de';
}elseif ($month == '9') {
$month = 'de septiembre de';
}elseif ($month == '10') {
$month = 'de octubre de';
}elseif ($month == '11') {
$month = 'de noviembre de';
}elseif ($month == '12') {
$month = 'de diciembre de';
}

$year = date ('Y');

print ("$day $date $month $year");

?>
</div>

Ness_du_Frat
04-16-2005, 12:57 PM
thanks a lot !!! I might use it. For what I'm doing, probably not, but it'll sure become of use sooner or later !!!
( I actually saw some of those in french too on different forums... )