Page 1 of 2

Posted: Sun Jul 21, 2002 7:56 pm
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;
?>

Posted: Mon Jul 22, 2002 7:30 am
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?

Posted: Mon Jul 22, 2002 7:40 am
by hob_goblin
yes, this really would take off, it's fun. and you could collect the final scripts and archive them, or something

Posted: Mon Jul 22, 2002 7:53 am
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...

Posted: Mon Jul 22, 2002 7:58 am
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.

Posted: Mon Jul 22, 2002 8:07 am
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...

Posted: Mon Jul 22, 2002 8:13 am
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;
?>

Posted: Mon Jul 22, 2002 8:24 am
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?!

Posted: Mon Jul 22, 2002 10:01 am
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)

Posted: Mon Jul 22, 2002 12:41 pm
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.

Posted: Mon Jul 22, 2002 2:46 pm
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;;
?>

Posted: Mon Jul 22, 2002 2:55 pm
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;
?>

Posted: Tue Jul 23, 2002 5:15 am
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;
?>

Posted: Tue Jul 23, 2002 8:27 am
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; 
?>

Posted: Tue Jul 23, 2002 8:37 am
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;