WebWork Magazin - Webseiten erstellen lassen, Online Medien, html

Webhoster, Webhosting Provider und Domain registrieren

Home | Registrieren | Einloggen | Suchen | Aktuelles | GSL-Webservice | Suleitec Webhosting
Reparatur-Forum | Elektro forum | Ersatzteilshop Haushalt und Elektronik


Homepage und Webhosting-Forum

Scripte und Programme für PHP, MYSQL. Diskussionen zur Programmierung im Web. Fragen zu CMS, Blogsoftware, Shops, Newsletter und vielen weiteren Scripten.


Forum » PHP & MySQL » Alter anzeigen » Antworten
Benutzername:
Passwort: Passwort vergessen?
Inhalt der Nachricht: Fett | Kursiv | Unterstrichen | Link | Bild | Smiley | Zitat | Zentriert | Quellcode| Kleiner Text
Optionen: Emailbenachrichtigung bei Antworten
 

Alter anzeigen
von DreamPromise
Hmmm..irgendwas stimmt noch immer nicht.

Nun zeigt er das aktuelle Jahr an.
Er soll aber zeigen wie alt derjeninge ist desse Geburtsdatum in der Datenbank steht.
von slackerbitch
wie rechnet man das alter nochmal aus...?
oder versteh ich was falsch?

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12:
// angenommen, das format des geburtstags ist so yyyy-mm-dd
// alter = dieses jahr - geburtsjahr
// ein jahr weniger, wenn dieses jahr noch keine party stattgefunden hat

list ($geb_jahr, $geb_monat, $geb_tag) = explode ('-', $gebdatum);
$alter = date ('Y') - $geb_jahr;
if (($geb_monat > date('m')) || (($geb_monat == date('m')) && ($geb_tag > date('d'))))
{
    $alter--;
}
von Philipp Gérard
1:
$query = mysql_query("SELECT * FROM user LIMIT 1",$db);


in

1:
$query = mysql_query("SELECT * FROM benutzer LIMIT 1",$db);
von DreamPromise
Hi

Schau doch mal nach--> http://www.jensschmelzer.info/alter.php


Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /www/htdocs/v035212/alter.php on line 58
2003
von Philipp Gérard
was kommt denn als fehler?
von DreamPromise
Hi

Na das hab ich doch auch schon gemacht...geht aber nicht.
von Philipp Gérard
1: 
2: 
3: 
4:
$db_server = "localhost";
$db_name = "selfphp";
$db_user = "root";
$db_passwort = "mega";


musst du auch anpassen ...
von DreamPromise
Hmmm...

Also bei mir kommt ne Fehlermeldung
von Philipp Gérard
gibt z.B. 18 aus.
von Philipp Gérard
also alles zusammen:

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48: 
49: 
50: 
51: 
52: 
53: 
54: 
55: 
56: 
57: 
58: 
59: 
60: 
61: 
62: 
63: 
64: 
65: 
66:
<?php

function ger2enDate($date)
{
   $date = explode(".", $date);
   $date = $date[2]."-".$date[1]."-".$date[0];
   return $date;
}

function getAge($birthday)
 {
   $today = getdate();
   $birthday = explode("-", $birthday);
 
   $birth_day = $birthday[2];
   $birth_month = $birthday[1];
   $birth_year = $birthday[0];
      
   $today_day = $today["mday"];
   $today_month = $today["mon"];
   $today_year = $today["year"];
   
   if (substr($birth_day, 0, 1) == "0")
     $birth_day = substr($birth_day, 1, 1);
   if (substr($birth_month, 0, 1) == "0")
     $birth_month = substr($birth_month, 1, 1);
   if (substr($birth_year, 0, 1) == "0")
     $birth_year = substr($birth_year, 1, 1);     
   if (substr($today_day, 0, 1) == "0")
     $today_day = substr($today_day, 1, 1);
   if (substr($today_month, 0, 1) == "0")
     $today_month = substr($today_month, 1, 1);
   if (substr($today_year, 0, 1) == "0")
     $today_year = substr($today_year, 1, 1);                
        
   if ($today_month > $birth_month)
     $age = $today_year - $birth_year;
   if ($today_month == $birth_month) {
     $age = $today_year - $birth_year;
     if ($today_day < $birth_day)
       $age--;
   }
   if ($today_month < $birth_month)
     $age = ($today_year - $birth_year) -1;      
     
   return $age;
}

$db_server = "localhost";
$db_name = "selfphp";
$db_user = "root";
$db_passwort = "mega";
         
$db = @MYSQL_CONNECT($db_server,$db_user,$db_passwort) or die ("Konnte keine Verbindung zur Datenbank herstellen");
$db_check = @MYSQL_SELECT_DB($db_name);

$query = mysql_query("SELECT * FROM user LIMIT 1",$db);
$row = mysql_fetch_row($query);

$alter = getAge(ger2enDate($row[1]));

echo $alter;

mysql_close($db);

?>
von Philipp Gérard
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14:
$db_server = "localhost";
$db_name = "selfphp";
$db_user = "root";
$db_passwort = "mega";
         
$db = @MYSQL_CONNECT($db_server,$db_user,$db_passwort) or die ("Konnte keine Verbindung zur Datenbank herstellen");
$db_check = @MYSQL_SELECT_DB($db_name);

$query = mysql_query("SELECT * FROM user LIMIT 1",$db);
$row = mysql_fetch_row($query);

$alter = getAge(ger2enDate($row[1]));

echo $alter;
von DreamPromise
Hi

Kannst da auch bei helfen ???
von Philipp Gérard
musste die daten auch erst auslesen...
von DreamPromise
Hi

So die Tabelle steht.
Ichhab schon was in die Tab reingeschrieben.
Kommt aber keine Ausgabe.

http://www.jensschmelzer.info/alter.php
von Philipp Gérard
-e

1: 
2: 
3: 
4: 
5: 
6:
CREATE TABLE `benutzer` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `geburtstag` varchar(255) NOT NULL default '',
  PRIMARY KEY (`id`)
) TYPE=MyISAM;
von DreamPromise
Hi

Kannste mir noch dabei helfen die anzulegen ?

1000 Danke
von Philipp Gérard
in eine MySQL-Tabelle.
von DreamPromise
Hi

Danke für die schnelle Hilfe.

Wo muß ich denn das Datum reinschreiben ?
von Philipp Gérard
1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
44: 
45: 
46: 
47: 
48:
function ger2enDate($date)
{
   $date = explode(".", $date);
   $date = $date[2]."-".$date[1]."-".$date[0];
   return $date;
}

function getAge($birthday)
 {
   $today = getdate();
   $birthday = explode("-", $birthday);
 
   $birth_day = $birthday[2];
   $birth_month = $birthday[1];
   $birth_year = $birthday[0];
      
   $today_day = $today["mday"];
   $today_month = $today["mon"];
   $today_year = $today["year"];
   
   if (substr($birth_day, 0, 1) == "0")
     $birth_day = substr($birth_day, 1, 1);
   if (substr($birth_month, 0, 1) == "0")
     $birth_month = substr($birth_month, 1, 1);
   if (substr($birth_year, 0, 1) == "0")
     $birth_year = substr($birth_year, 1, 1);     
   if (substr($today_day, 0, 1) == "0")
     $today_day = substr($today_day, 1, 1);
   if (substr($today_month, 0, 1) == "0")
     $today_month = substr($today_month, 1, 1);
   if (substr($today_year, 0, 1) == "0")
     $today_year = substr($today_year, 1, 1);                
        
   if ($today_month > $birth_month)
     $age = $today_year - $birth_year;
   if ($today_month == $birth_month) {
     $age = $today_year - $birth_year;
     if ($today_day < $birth_day)
       $age--;
   }
   if ($today_month < $birth_month)
     $age = ($today_year - $birth_year) -1;      
     
   return $age;
}

$alter = getAge(ger2enDate($data[birth]));


Datum so speichern:

1:
11.9.1985 


oder halt als Timestamp, dann mit

1:
date("D.m.Y",$date);


umwandeln und dann durch diese funktionen laufen lassen.
von DreamPromise
Hi Leute

Ich hab ne PHP-Seite und möchte dort angezeigt bekommen wie alt jemand ist.

Das geburtsdatum müßte man irgendwo/irgendwie ablegen.

Wie geht sowas ?

Gruß JENS


Nach oben