TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Show Off (http://www.talkphp.com/show-off/)
-   -   Your old code? (http://www.talkphp.com/show-off/1354-your-old-code.html)

Andrew 10-29-2007 03:55 AM

Your old code?
 
Well, I was feeling a bit bored and nostalgic, so I went through all my threads at various forums, and found all my design and PHP work I did back then. Here is the PHP work I found, thought you guys might enjoy seeing how horrible I was. This was from over 2 years ago (August/September '05). I'm rather sad knowing I could have kept coding PHP, and be pretty good by now.

This script never did work, by the way. Now I see why. :)

(I'm just linking to my site since they are rather long and have HTML code mixed in for forms)
http://www.psdtocode.com/old.phps
http://www.psdtocode.com/old2.phps

bluesaga 10-29-2007 10:18 AM

Lol ouch, i do not have the code but when i was learning i use to have switches and paste the entire html template into each switch case like:

PHP Code:

switch ($state)
{
   case 
"home":
      
//full html doc and php inserting variables, including header and footer. no includes, just copy + paste html
   
break;
   case 
"account":
      
//full html doc and php inserting variables, including header and footer no inlcudes just copy + paste html
   
break;


Note this was like 2002 and i would of been like 14... lol

Wildhoney 10-29-2007 01:20 PM

Lol. I remember I always used to use <?=$myVariable; ?> when I was coding years ago. I must dig out some of my old code though! I'm sure it'll tickle you all.

cherries 10-29-2007 04:00 PM

My old code would be something like this:
PHP Code:

<?php
include('connect.php');
global 
$db;

if(
$db == null){
    die(
'LOL! You could not connect to DB!!! LOL!!');
}

if(
$_POST['submit']){
     
$HUGELISTOFVARIABLES $_POST['stuff'];

     
$result mysql_query('SOME HUGE QUERY');
     if(
$result){
         echo 
"AWESOME! LOL!!!";
     }
}else{
//HUGE FORM HTML
}
?>

as compared to now:
PHP Code:

<?php
    
class template
    
{
        private 
$code;

        public function 
__construct $szFile )
        {
            
$this->code file_get_contents($szFile);
        }
        
        public function 
replaceVars $aVars )
        {
            foreach ( 
$aVars as $key => $value )
            {
                
$this->code str_replace($key$value$this->code);
            }
        }
        
        public function 
publish ( )
        {
            echo 
$this->code;
        }
    }
    
    
/***
    * Example Usuage:
        $tpl = new template('templates/xtc.tpl');
        $tpl->replaceVars(array('HOME_URL' => 'http://www.google.com'));
        $tpl->publish();
    */
?>


Haris 10-29-2007 06:05 PM

PHP Code:

<?php echo 'Hello World'?>

I started out with echos.

Wildhoney 10-29-2007 09:32 PM

Yeah, I used to mix all my PHP with my HTML. Lovely stuff!

Wildhoney 10-29-2007 09:51 PM

Quote:

Originally Posted by Haris (Post 3486)
PHP Code:

<?php echo 'Hello World'?>

I started out with echos.

I don't get it. What's wrong with echoes?

Andrew 10-29-2007 10:29 PM

He was saying that is how he started coding, with the basic Hello World script.

Also, on the Chatwebdev IRC channel, Dread (a great PHP coder), and Shaun were also digging out their old code, too. See what I started? :)

Village Idiot 10-30-2007 12:02 AM

Here is a crappy under-featured forum I made with about two months of PHP experience.

http://www.justanotherportfolio.com/forum.zip

bdm 11-29-2007 06:07 PM

Quote:

Originally Posted by bluesaga (Post 3460)
PHP Code:

switch ($state)
{
   case 
"home":
      
//full html doc and php inserting variables, including header and footer. no includes, just copy + paste html
   
break;
   case 
"account":
      
//full html doc and php inserting variables, including header and footer no inlcudes just copy + paste html
   
break;



LOL

When I first got into PHP, a friend of mine told me how he made all of his dynamic sites using only one file (index.php). I couldn't believe my eyes! I was amazed and used it on a few sites until I saw the downfall. Although, my index.php used if statements as if they were going out of style. Actually, I didn't even know what a switch statement was either. The worse part of it all was that I didn't put a common header and footer in my index.php. Each 'page' would contain EVERYTHING including the doctype. Needless to say, updating my site sucked ass.

Not too long later, someone told me about seperating my header and footer into their own entity and simply including them on the top and bottom of my script. I nearly soiled mysql when I learned this nifty trick.

:)

sketchMedia 11-29-2007 06:47 PM

I'd be toooo embarrassed to post my code, but lets say i didnt bother seperating presentation from logic

Wildhoney 11-29-2007 09:25 PM

Quote:

Originally Posted by sketchMedia (Post 4794)
I'd be toooo embarrassed to post my code, but lets say i didnt bother seperating presentation from logic

Oh go on! If my PC actually worked without me kicking it to get its hard-drives whirring again, I'd pull up some of my old code :-).

sketchMedia 11-29-2007 11:29 PM

ok, I'll see what i can find.:-$

Wildhoney 11-30-2007 02:30 AM

I'll get the tissues ready for when laughter results in tears!

Wildhoney 12-01-2007 04:40 PM

Hehe. I found some of my old code. This is a snippet from my Javascript hangman game which is still quite addictive! The RAR file is dated the 12th of Match, 2006, so you can see how far I've come. Without further ado:

(I would edit the DB details, but it's years old anyway.)

php Code:
define('MS_GAME', 'GAME'.substr(rand(99999, 10000).ip2long($_SERVER['REMOTE_ADDR']), 0, 12));
define('MYSQL_USER', 'adam_mine05user');
define('MYSQL_PASS', 'sYi3haVveV39qQ');
define('MYSQL_HOST', 'localhost');
define('MYSQL_DB', 'adam_minesweeper');
ini_set('max_execution_time', '120');

$minesweeperSQL = @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die('<div style="font-size: 10px; font-family: Tahoma, Verdana, Helvetica">MySQL Server not responding.</div>');
@mysql_select_db(MYSQL_DB) or die('<div style="font-size: 10px; font-family: Tahoma, Verdana, Helvetica">MySQL database "'.MYSQL_DB.'" does not exist.</div>');

if(isset($_GET['records'])) {
    $level = mysql_real_escape_string(strip_tags($_GET['records']));
    $sql = "SELECT rName, rTime FROM `records` WHERE rLevel = '$level' ORDER BY rTime ASC LIMIT 0,10";
    $resultsRS = mysql_query($sql);
    $records = '<table id="records"><tr id="record"><th style="width: 10px"></th><th style="width: 120px">Name</th><th>Time (Seconds)</th>';
    $n = 1;
    while($row = mysql_fetch_array($resultsRS)) {
        $records .= '<tr><td>'.$n.'</td><td>'.$row['rName'].'</td><td>'.$row['rTime'].'</td></tr>';
        $n++;
    }
    $records .= '</tr></table>';
    echo $records;
    mysql_free_result($resultsRS);
    die();
} elseif(isset($_GET['name']) && isset($_GET['seconds'])) {
    function microtime_float() {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    $time_start = mysql_real_escape_string(strip_tags($_GET['seconds']));
    $time_end = microtime_float();
    $time = $time_end - $time_start;
    $name = substr(mysql_real_escape_string(strip_tags($_GET['name'])), 0, 40);
    $level = mysql_real_escape_string(strip_tags($_GET['level']));
    $level = $_GET['level'];
    setcookie('Minesweeper', $name);
    $sql = "INSERT INTO `records` (rName, rLevel, rTime) VALUES ('$name', '$level', '$time')";
    mysql_query($sql);
} elseif(isset($_GET['cell']) && isset($_GET['game'])) {
    $cell = substr(mysql_real_escape_string($_GET['cell']), 0, 3);
    $game = $_GET['game'];
    $sql = "SELECT `gValue` FROM `game` WHERE gCell = '$cell' AND gID = '$game'";
    $resultsRS = mysql_query($sql);
    $row = mysql_fetch_array($resultsRS);
    if($row == 0) {
        echo $row[0];   
    }
    elseif($row[0] == 'Mine') {
        echo $row[0];
        die()
    } else {
        switch($row[0]) {
            case(1):
                $number = 1;
                $colour = '#5B35FF';
                break;
            case(2):
                $number = 2;
                $colour = '#007103';
                break;
            case(3):
                $number = 3;
                $colour = '#FF3535';
                break;
            case(4):
                $number = 4;
                $colour = '#002B8C';
                break;
            case(5):
                $number = 5;
                $colour = '#910202';
                break;
            case(6):
                $number = 6;
                $colour = '#00A997';
                break;
            case(7):
                $number = 7;
                $colour = '#000000';
                break;
            case(8):
                $number = 8;
                $colour = '#CB9900';
                break;
            default;
                $number = 0;
                $colour = '#000000';
                break;
        }   
    }
    echo '<font color="'.$colour.'">'.$number.'</font>';
    mysql_free_result($resultsRS);
    die();
}

Hopefully I've laid a foundation :-) Don't be shy anybody!

WinSrev 12-01-2007 06:13 PM

That's pretty cool, i lost all my old code, not sure where i went :(
The oldest code i have is about a year old which as my original social networking site, but that's a secret ;)

Haris 12-01-2007 07:56 PM

php Code:
<?php

// Last Modified 18th August

include('templates/header.php'); // Header template
include('config/config.php'); // Includes configuration files
include('lib/functions.php'); // Load all functions from Library

$select_questions = mysql_query("SELECT * FROM questions") or die(mysql_error());
while($row = mysql_fetch_array($select_questions, MYSQL_BOTH)){
    $questions = $row['question'];
    $qID = $row['id'];
    if($_POST[$qID] == "Positive"){
        $_POST[$qID] = 1;
    }
    elseif($_POST[$qID] == "Negative"){
        $_POST[$qID] = 2;
    }
    else{
        $_POST[$qID] = 3;
    }
    $posted_answer[] = $_POST[$qID];
}

$submit_useranswer = $_POST['submit_useranswers'];
if(isset($submit_useranswer)){
    $user_answer[] = $posted_answer;
    echo '<h2>Top three nearest candidates based on your answers</h2>';
    include('templates/table.php');
}

include('templates/footer.php'); // Footer Template

?>

sketchMedia 12-01-2007 08:12 PM

I cant actually find the code, i think if was lost when my last HD packed in.

But the script was someting i wrote for the CoD1/2 game server hosting company i used to run.
It was basically the order form, it had about 6 different forms on it and it was ALL in one php file with a switch at the top, with HTML/CSS and PHP mixed all over the shop.
It was a right mess and a nightmare to maintain, as you can imagine.
If i do find it i will post it.

Wildhoney 12-04-2007 04:03 AM

Not too bad, Haris. At least you're sectioning off different code. I think mine looks a lot worse than yours. Can definitely see how far we've come when you look over your old code!

Haris 12-04-2007 04:16 AM

Quote:

Originally Posted by Wildhoney (Post 5200)
Not too bad, Haris. At least you're sectioning off different code. I think mine looks a lot worse than yours. Can definitely see how far we've come when you look over your old code!

I think it's because I had joined a proper community (TalkPHP) that helped me program things correctly. 8-)


All times are GMT. The time now is 12:01 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0