logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 03-05-2008, 01:45 PM   #1
moe122
 
Join Date: Feb 2008
Posts: 138
Default 3 smal problemz :)

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]
moe122 is offline   Reply With Quote
Old 03-05-2008, 02:17 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

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!

Quote:
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.

Quote:
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.

Quote:
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]
PHP Code:
echo $rowAccount['val1'].$rowAccount['val2'
or if you need a space between them
PHP Code:
echo $rowAccount['val1']." ".$rowAccount['val2'
remember that . is used to concatenate 2 values
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-05-2008, 06:38 PM   #3
moe122
 
Join Date: Feb 2008
Posts: 138
Default

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
moe122 is offline   Reply With Quote
Old 03-05-2008, 08:18 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

here is a clue

PHP Code:
$bdate $_POST['bdate'];
 
/// current date
$cday date("d");
$cmonth date("m");
$cyear date("Y");
 
/// birthdate from POST above
$bday     =  substr($bdate0,2);
$bmonth  =  substr($bdate3,2);
$byear    =  substr($bdate6,4); 
ok

the above will get both dates required and split them into their component parts ready for your calculations
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-06-2008, 01:18 AM   #5
moe122
 
Join Date: Feb 2008
Posts: 138
Default

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.....
moe122 is offline   Reply With Quote
Old 03-06-2008, 06:51 AM   #6
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

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

Quote:
2008/03/06
imagine counting each char in that date but start at 0

in our substr function to get the year we use

PHP Code:
$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 <-- ?
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-06-2008, 06:02 PM   #7
moe122
 
Join Date: Feb 2008
Posts: 138
Default

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

PHP Code:
$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_Birth8,2);
$bmonth  =  substr($Date_of_Birth5,2);
$byear    =  substr($Date_of_Birth0,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 is offline   Reply With Quote
Old 03-07-2008, 04:57 PM   #8
moe122
 
Join Date: Feb 2008
Posts: 138
Default

could i get some help plz?
moe122 is offline   Reply With Quote
Old 03-07-2008, 08:29 PM   #9
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

err i didnt hear the click of a donate button so demanding help doesnt cut the mustard
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 03-07-2008, 09:49 PM   #10
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

a different method wrapped in a function...

PHP Code:
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..
PHP Code:
echo age("19-08-1968"); //<< date of birth 
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com