Previous Thread
Next Thread
Print Thread
Rate Thread
#257325 08/22/2003 12:21 AM
Joined: May 2002
Posts: 362
Junior Member
Junior Member
Offline
Joined: May 2002
Posts: 362
Okay, this may sound weird, but I gotta believe it's completely doable and will work.

I created a script that basically shows a list of the latest 15 users


Username - Registered DOB - link to profile


I'm using Dave's DOB thing to catch the bday they register with. To my knowledge it stores the date in the database in "0000-00-00" form.... I could be wrong though...

Anyway, what I'd like to do, is somehow add something in there to say

If DOB is 23+(compared to the current day) THEN show the link to the profile, else nothing.

I'm looking at the adduser stuff and see a way to do it, though I guess I don't understand how to work with the format of the DOB variable the way it's set up....

Any help would be muchly appreciated!

-peter

Sponsored Links
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
The column type is DATE (a predefined MySQL column type), which is represented as 'YYYY-MM-DD' if you extract the column as a string.

Are you saying you want to check whether the person's age is >= 23 years?

MySQL has built-in functions for doing date arithmetic. For example, this query will select users whose age is >= 23 years:
SELECT * FROM w3t_Users WHERE U_DOB <= DATE_SUB(NOW(), INTERVAL 23 YEAR)

Last edited by Dave_L; 09/02/2003 7:58 AM.
Joined: May 2002
Posts: 362
Junior Member
Junior Member
Offline
Joined: May 2002
Posts: 362
Yeah, basically, I want it to show a link if the date is >=23 years.



In all, I want the latest 15 users that have regged with their bdays to be shown. This much I have. Then, in a third column, I'm thinking an if clause to say if >=23 then show the link to profile, and if they're under then show nothing in that column.

Thanks for working with me, plus, you usually explain it in a way that let's me work on harder things.

Joined: May 2002
Posts: 362
Junior Member
Junior Member
Offline
Joined: May 2002
Posts: 362
Dave, I still haven't gotten it to work quite yet...

Any more advice?

Again, I just want it to show a link if they're over 23, and if not, I just want nothing displayed....

Joined: May 2002
Posts: 362
Junior Member
Junior Member
Offline
Joined: May 2002
Posts: 362
Blah, I'm trying, I really am... lol


Can anyone tell me what's wrong with this? It's just not working the way it'supposed to...


Code
  <br /><br /> if ($DOB >= "DATE_SUB(NOW(), INTERVAL 23 YEAR)") {<br />         $DOB = " <TD class=\"$color\"> LINK HERE </TD></TR>\n";<br />      }<br />      else {<br />         $DOB = " <TD class=\"$color\"> NO LINKE HERE </TD></TR>\n";<br />      }<br />  


So, it's supposed to evaluate things this way:

If the DOB is 23 or greater, then LINK shows, if not, NO LINK shows...

Something is wrong though, cause I get no page and just errors...

If it'd help, I can post the entire script I'm using..

-peter

Sponsored Links
Joined: Jun 2003
Posts: 1,025
Junior Member
Junior Member
Offline
Joined: Jun 2003
Posts: 1,025
Is it giving any kind of error or is it just not showing. Is this the exact code you are trying to use?

$DOB = " <TD class="$color"> LINK HERE </TD></TR>\n"

This string looks wrong to me for 2 reasons.
1. the space between the " and <TD doesn't seem like it should be there.

2. the $DOB = statement in the then part seems to be using that varible incorrectly. I'm not sure exactly how it should be, but right now I read it as:
If $DOB is greater than or equal to 23 years, then $DOB equals " <TD class="$color"> LINK HERE </TD></TR>\n",
else $DOB equals $DOB = " <TD class="$color"> NO LINKE HERE </TD></TR>\n"

That seems like you're just overwriting your varible with data that can't really be used.

I could be way off here, and I probally am, but looking at it logically, that is what I see.

Joined: May 2002
Posts: 362
Junior Member
Junior Member
Offline
Joined: May 2002
Posts: 362
Bleh... I have no clue.. Oh well, at least I tried.

Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
Code
if ($DOB >= "DATE_SUB(NOW(), INTERVAL 23 YEAR)") {


That won't work, because DATE_SUB is a MySQL function. It can only be used within a MySQL query.

Do something like this:

Code
$sth = $dbh->do_query(" <br />   SELECT <br />      U_Number, <br />      U_Username, <br />      /* 1 if U_DOB is at least 23 years ago, 0 otherwise */ <br />      IF (U_DOB <= DATE_SUB(NOW(), INTERVAL 23 YEAR), 1, 0) AS OVER_23 <br />   FROM w3t_Users <br />   ORDER BY U_Registered DESC <br />   LIMIT 15 <br />"); <br /> <br />while (list($uid, $username, $over_23) = $dbh->mysql_fetch_row($sth)) { <br />   if ($over_23) { <br />      ... do something <br />   } else { <br />      ... do something else <br />   } <br />}

Last edited by Dave_L; 09/02/2003 8:03 AM.
Joined: May 2002
Posts: 362
Junior Member
Junior Member
Offline
Joined: May 2002
Posts: 362
Thanks Dave, that should be what I need... I'll work on it soon!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
hatter
hatter
USA
Posts: 69
Joined: January 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240506)