http://www.udvikleren.dk/forum/40134/foedselsdato-systemindlæg Ronny Jørn Olsen @ 25.07.13 15:40
når det ligger i databasen er dette indlæg interessant
http://www.udvikleren.dk/forum/38884/foedselsdag-system 02.10.12 08:17
ref
http://ma.tt/2003/12/calculate-age-in-mysql/
$sql = "SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(dob)), '%Y')+0 AS age FROM people";
eller
$sql = "SELECT DATE_FORMAT(NOW(), '%Y') - DATE_FORMAT(dob, '%Y') - (DATE_FORMAT(NOW(), '00-%m-%d') < DATE_FORMAT(dob, '00-%m-%d')) AS age FROM people";
kig på disse 2 eks
<?php
/*
CREATE TABLE IF NOT EXISTS `brugere` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`brugernavn` varchar(255) COLLATE utf8_danish_ci NOT NULL,
`alder` int(11) NOT NULL,
`dob` date NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci AUTO_INCREMENT=3 ;
INSERT INTO `brugere` (`id`, `brugernavn`, `alder`, `dob`) VALUES
(1, 'lasse', 18, '2013-08-11'),
(2, 'ronny', 0, '1966-11-10');
*/
if(! isset($_SESSION)){
session_start();
}
include_once($_SERVER['DOCUMENT_ROOT']."/include/php/debugheader.php"); // for at vise alle fejl og advarsler
require_once($_SERVER['DOCUMENT_ROOT']."/include/php/db/mysqlconnection.php");
$conn=MySqlIConnOOP();
// lasse,
$_SESSION['brugernavn']="lasse";
$alder=0;
$sql = "SELECT alder FROM brugere WHERE brugernavn ='".$_SESSION['brugernavn']."'";
$rs = $conn->query($sql);
if($rs){
$row = $rs->fetch_assoc();
$alder = $row['alder'];
$rs->free();
}
echo $_SESSION['brugernavn']." er " .$alder. "<br>";
// ronny, her beregner sql det selv, hvilke er det smarteste
$_SESSION['brugernavn']="ronny";
$alder=0;
$sql = "SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(dob)), '%Y')+0 AS age FROM brugere WHERE brugernavn = '".$_SESSION['brugernavn']."'";
$rs = $conn->query($sql);
if($rs){
$row = $rs->fetch_assoc();
$alder = $row['age'];
$rs->free();
}
echo $_SESSION['brugernavn']." er " .$alder. "<br>";
?>
skal lige læse det opdateret indlæg
opdate:
kig på denne
<?php
/*
CREATE TABLE IF NOT EXISTS `sb_admins` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`authid` int(11) NOT NULL,
`srv_group` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci AUTO_INCREMENT=3 ;
INSERT INTO `sb_admins` (`id`, `authid`, `srv_group`) VALUES
(1, 1, 5),
(2, 4, 7);
*/
$steam_id=1;
$sql = mysql_query("SELECT srv_group FROM sb_admins WHERE authid = $steam_id");
$rows = mysql_fetch_assoc($sql);
echo "Dit SteamID: <b>" . $steam_id . "</b><br><br></center>";
echo "<ul> <li>Rank: <b>" . $rows['srv_group'] . "</b></li> <li>Udløber om: <b>Aldrig</b></li> <li>Credits i !Store: <b>1502 Credits</b></li> </ul>";
du skyder dig selv i foden med stor kaliber, ved at bruge det gamle API
ref
http://php.net/mysql_query
Warning
This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_query()
PDO::query()
Indlæg senest redigeret d. 11.08.2013 12:27 af Bruger #16075