PHP Tennis Match 2

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Ok, here's match #2:

Sudden death (free for all)
Max lines per edit: 5
Time limit: None

http://www.zend.com/codex.php?id=309&single=1

Code: Select all

<?php
function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
    $iDays = $iTimeStamp / 86400;
    $iYears = floor($iDays / 365.25);
    return $iYears;

&#125;
?>
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post by enygma »

Alright - so who thinks this would make for a good site on it's own? I spent the weekend outlining something that I think would work, but I need to get it all typed up and posted so that you guys could take a look at it.

Basically, it would work the same way as this would, just with more structure. There would be the possibility of "open matches" where anyone could view/join in as long as they have a username on the site, as well as private matches that would be "view-only" to everyone else except those involved.

The site would take care of storing the "turns" in a database and emailing the other people when it was their turn to go...

I think something like this could really take off, and I'd love to work on it. I was going to start it up and then present it to you all, but I figured I'd get your opinion first and see how it went from there.....

Ideas? Suggestions?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

yes, this really would take off, it's fun. and you could collect the final scripts and archive them, or something
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

Yeah, that would be great. Have different sections like:

PHP
-- Sudden Death
-- One-On-One
-- (etc)
ASP
-- Sudden Death
-- One-On-One
-- (etc)
JSP
-- Sudden Death
-- One-On-One
-- (etc)

And so on, as well as perhaps a seperate general discussion forum.

As for the archive, that would be pretty cool too. Make it so users can post the final code instead of the admins having to do it all. I think one of the reasons this 'game' was started was to develop code...
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

Code: Select all

<?php
function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123;
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
        $iDays = $iTimeStamp / 86400;
        $iYears = floor($iDays / 365.25);
        return $iYears;
    &#125; else &#123;
        return "Missing argument.";
    &#125;
&#125;
?>
Began error trapping.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

<?php 
$link = mysql_connect("localhost", "user", "pass");
mysql_select_db("db");

function getAgeByDate($iMonth, $iDay, $iYear) &#123; 
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123; 
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear); 
        $iDays = $iTimeStamp / 86400; 
        $iYears = floor($iDays / 365.25); 
        mysql_query("INSERT INTO ages (age) values ('$iYears')");
        return $iYears; 
    &#125; else &#123; 
        return "Missing argument."; 
    &#125; 
&#125; 

?>
we might as well record it...
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

Code: Select all

<?php
// Example: storeAge(getAgeByDate(2,19,1986))

function storeAge($age) &#123;
    $link = mysql_connect("localhost", "user", "pass"); 
    mysql_select_db("db"); 
    mysql_query("INSERT INTO ages (age) values ('$age')"); 
&#125;

function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123;
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
        $iDays = $iTimeStamp / 86400;
        $iYears = floor($iDays / 365.25);
        return $iYears;
    &#125; else &#123; 
        return "Missing argument.";
    &#125;
&#125;
?>
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

Just out of interest protokol, did you nick that script idea from the SitePoint Forums, or is jsut conincidence that they started the same match?!
samscripts
Forum Commoner
Posts: 57
Joined: Tue Apr 23, 2002 4:34 pm
Location: London, UK

Post by samscripts »

why not have an ASP vs PHP vs JSP vs PERL etc section - someone posts something in one language, others have to create the same in the other languages? Could be quite useful for people with knowledge of one trying to learn another?

Sam

Hex Wrote:
Yeah, that would be great. Have different sections like:

PHP
-- Sudden Death
-- One-On-One
-- (etc)
ASP
-- Sudden Death
-- One-On-One
-- (etc)
JSP
-- Sudden Death
-- One-On-One
-- (etc)
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

let me try my hand at this:

Code: Select all

<?php
function storeAge($age) &#123;
	//provide error handling on DB errors
    $link = @mysql_connect("localhost", "user", "pass") 
        or die("connect failed");
    mysql_select_db("db");
    $result = @mysql_query("INSERT INTO ages (age) values ('$age')") 
        or die("query failed");
&#125;

function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123;
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
        $iDays = $iTimeStamp / 86400;
        $iYears = floor($iDays / 365.25);
        return $iYears;
    &#125; else &#123;
        return "Missing argument.";
    &#125;
&#125;
?>
Just a question: what about the 80-char per line rule? the original post violated it.
duke9
Forum Newbie
Posts: 7
Joined: Thu May 23, 2002 4:17 pm

Post by duke9 »

Since it's not generally considered polite to ask a woman how old she is ..

Code: Select all

<?php
function storeAge($age) &#123;
	//provide error handling on DB errors
    $link = @mysql_connect("localhost", "user", "pass") 
        or die("connect failed");
    mysql_select_db("db");
    $result = @mysql_query("INSERT INTO ages (age) values ('$age')") 
        or die("query failed");
&#125;

function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123;
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
        $iDays = $iTimeStamp / 86400;
        $iYears = floor($iDays / 365.25);
        return $iYears;
    &#125; else &#123;
        return "Missing argument.";
    &#125;
&#125;

// f_ prefix marks variables from a form
$age = getAgeByDate($f_mon,$f_day,$f_year);
if (is_int($age)) &#123;
         sprint("You are $age years %s.",($f_gender == "female") ? "young" : "old");
&#125;;
?>
terryf
Forum Newbie
Posts: 1
Joined: Mon Jul 22, 2002 2:55 pm

Post by terryf »

Code: Select all

<?php 
function storeAge($age) &#123; 
   //provide error handling on DB errors 
    $link = @mysql_connect("localhost", "user", "pass") 
        or die("connect failed"); 
    mysql_select_db("db"); 
    $result = @mysql_query("INSERT INTO ages (age) values ('$age')") 
        or die("query failed"); 
&#125; 

function getAgeByDate($iMonth, $iDay, $iYear) &#123; 
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123; 
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear); 
        $iDays = $iTimeStamp / 86400; 
        $iYears = floor($iDays / 365.25); 
        return $iYears; 
    &#125; else &#123; 
        return "Missing argument."; 
    &#125; 
&#125; 

// functions are nice
function getAgeString($sGender, $iMonth, $iDay, $iYear) &#123; 
	$age = getAgeByDate($iMonth, $iDay, $iYear); 
	if (is_int($age)) &#123; 
	         return "You are $age years ".(($sGender == "female") ? "young" : "old"); 
	&#125;; 
&#125;
?>
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

Code: Select all

<?php 
function storeAge($age) &#123;
    if ($age) &#123;
        $link = @mysql_connect("localhost", "user", "pass")
            or die("<b>Database connect failed.</b>");
        mysql_select_db("db");
        $result = @mysql_query("INSERT INTO ages (age) values ('$age')")
            or die("<b>Database query failed.</b>");
    &#125;
&#125;

function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123;
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
        $iDays = $iTimeStamp / 86400;
        $iYears = floor($iDays / 365.25);
        return $iYears;
    &#125; else &#123;
        return false;
    &#125;
&#125;

function getAgeString($sGender, $iMonth, $iDay, $iYear) &#123;
   $age = getAgeByDate($iMonth, $iDay, $iYear);
   if (is_int($age)) &#123;
       return "You are $age years ".(($sGender == "female") ? "young" : "old");
   &#125;
&#125;
?>
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

<?php 
function storeAge($age) &#123; 
    if ($age) &#123; 
        $link = @mysql_connect("localhost", "user", "pass") 
            or die("<b>Database connect failed.</b>"); 
        mysql_select_db("db"); 
        $result = @mysql_query("INSERT INTO ages (age) values ('$age')") 
            or die("<b>Database query failed.</b>"); 
    &#125; 
&#125; 

function getAgeByDate($iMonth, $iDay, $iYear) &#123; 
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123; 
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear); 
        $iDays = $iTimeStamp / 86400; 
        $iYears = floor($iDays / 365.25); 
        return $iYears; 
    &#125; else &#123; 
        return false; 
    &#125; 
&#125; 

function getAgeString($sGender, $iMonth, $iDay, $iYear) &#123; 
   $age = getAgeByDate($iMonth, $iDay, $iYear); 
   if (is_int($age)) &#123; 
       return "You are $age years ".(($sGender == "female") ? "young" : "old"); 
   &#125; else&#123;
      return false;
   &#125;
&#125; 
?>
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

Code: Select all

<?php
function storeAge($age) &#123;
    if ($age) &#123;
        $link = @mysql_connect("localhost", "user", "pass")
            or die("<b>Database connect failed.</b>");
        mysql_select_db("db");
        $result = @mysql_query("INSERT INTO ages (age) values ('$age')")
            or die("<b>Database query failed.</b>");
    &#125;
&#125;

function getAgeByDate($iMonth, $iDay, $iYear) &#123;
    if (!empty($iMonth) && !empty($iDay) && !empty($iYear)) &#123;
        $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear);
        $iDays = $iTimeStamp / 86400;
        $iYears = floor($iDays / 365.25);
        return $iYears;
    &#125; else &#123;
        return false;
    &#125;
&#125;

//seems like everywhere but the USA a 20-year old (like me) can drink...
function isLegalToDrink($iMonth, $iDay, $iYear, $iCountry) &#123;
   $age = getAgeByDate($iMonth, $iDay, $iYear);
   if(is_int($age) && (($age > 18 && strcasecmp($iCountry,"USA")) || ($age > 21 && !strcasecmp($iCountry,"USA"))))
        return "You are legal to drink alcohol";
   else
        return "You have " . (21 - $age) . " year(s) left until you can drink";
&#125;
Post Reply