PDA

View Full Version : 3 smal problemz :)


moe122
03-05-2008, 01:45 PM
hey david,

1st 1z how can i work out age using DOB and then echo it
2nd iz ur login tut.....say if u close the window instead of login off u can access the welcome page by enterin it in2 the browser is that a problem?
3 say i want 2 echo 2 values from a database (value 1,value 2)how do i write it out, instead of writing it separately as 2 php codes .....echo $rowAccount['val1'] , echo $rowAccount[val2]

davidj
03-05-2008, 02:17 PM
Moe I'm 40. Please converse with me in English. I have to write a decryption algorithm to understand some of your posts. Sorry i cant get down with the kids but I'm an old git!


1st 1z how can i work out age using DOB and then echo it


this is just math moe

surely this is not beyond you.


2nd iz ur login tut.....say if u close the window instead of login off u can access the welcome page by enterin it in2 the browser is that a problem?


yes if you don't log off correctly people can access the site by just recalling the secure page because their session still exists.

The session will expire after 20 Min's which is driven by the web server.


3 say i want 2 echo 2 values from a database (value 1,value 2)how do i write it out, instead of writing it separately as 2 php codes .....echo $rowAccount['val1'] , echo $rowAccount[val2]



echo $rowAccount['val1'].$rowAccount['val2']

or if you need a space between them

echo $rowAccount['val1']." ".$rowAccount['val2']

remember that . is used to concatenate 2 values

moe122
03-05-2008, 06:38 PM
ok worked out what i want 2 do but dont know how 2 do it.......


well basically going to get current date ('d/m/y')
and get date of birth ('d1/m1/y1')

do m1-m and if it is > 0 .........age = y-y1
if it iz < 0 ..........age = y-y1-1
if = 0 then we check d1-d if its > or = 0 the age = y-y1
if not then age = y-y1-1

davidj
03-05-2008, 08:18 PM
here is a clue


$bdate = $_POST['bdate'];

/// current date
$cday = date("d");
$cmonth = date("m");
$cyear = date("Y");

/// birthdate from POST above
$bday = substr($bdate, 0,2);
$bmonth = substr($bdate, 3,2);
$byear = substr($bdate, 6,4);


ok

the above will get both dates required and split them into their component parts ready for your calculations

moe122
03-06-2008, 01:18 AM
the DOB is going to be fetched from the database....so would there be some more code? because theres something wrong with the DOB part, i dont even think its getting the values.....

davidj
03-06-2008, 06:51 AM
if the dob is being pulled from the database then remember that its stored in this format....

yyyy-mm-dd

so we use substr function which requires 3 arguments

So $bdate is now being populated by $row['birthdate'];


ok so the first argument is the var $bdate

the next two numerics work like this

lets look at this date

2008/03/06

imagine counting each char in that date but start at 0

in our substr function to get the year we use

$byear = substr($bdate,0,4);

start at 0 and move 4 chars in. This will assign 2008 to the $byear variable

do you understand?... or is ya gizzle in ya fizzle <-- ?

moe122
03-06-2008, 06:02 PM
wahz happenin david?
ok i've got the following but theres something wrong.....ive echoed all values frm date_of_birth to check initial stage of getting the values from the database....and when $cmonth = $bmonth it echoes 0 instead of the 03 as in march


$Date_of_Birth = $rowAccount['Date_of_Birth'];

/// current date
$cday = date("d");
$cmonth = date("m");
$cyear = date("Y");

/// birthdate from POST above
$bday = substr($Date_of_Birth, 8,2);
$bmonth = substr($Date_of_Birth, 5,2);
$byear = substr($Date_of_Birth, 0,4);
$a = $cyear - $byear;
$b = $cyear - $byear - 1;
if($cmonth - $bmonth > 0){$Age = $a;
}elseif($cmonth - $bmonth < 0){$Age = $b;
}
if($cmonth - $bmonth = 0){if($cday - $bday >= 0){$Age = $a;
}elseif($cday - $bday < 0){$Age = $b;
}
}

moe122
03-07-2008, 04:57 PM
could i get some help plz?

davidj
03-07-2008, 08:29 PM
err i didnt hear the click of a donate button so demanding help doesnt cut the mustard

davidj
03-07-2008, 09:49 PM
a different method wrapped in a function...


function age($birthday) {

list($day,$month,$year) = explode("-",$birthday);

$Ydiff = date("Y") - $year;
$Mdiff = date("m") - $month;
$Ddiff = date("d") - $day;

if ($Mdiff < 0) {

$Ydiff--;

}elseif (($Mdiff==0) && ($Ddiff < 0)) {

$Ydiff--;

}

return $Ydiff;

}



call the fuction like so..

echo age("19-08-1968"); //<< date of birth

moe122
03-12-2008, 10:44 PM
i just saw your reply to this now.....sorry, i figured this out straight after i posted for some help....and as for donations.....im just a kid.....

davidj
03-13-2008, 07:35 AM
im just a kid.....


yes i know

you were either a kid or a rapper... i guessed kid