Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:39:33+00:00 2026-06-15T15:39:33+00:00

I have a very rough script for the monotonous task of populating one of

  • 0

I have a very rough script for the monotonous task of populating one of my database tables with teams attending different events every year. But it would be a lot nicer if I didn’t have to go back and correct the year in the database every time.

I have a table of yearly events that gets queried, which in turn allows the script to fetch the list of teams for that event. The year is set using the following:

$year = date('Y');

For each team-event-year combination the following query fires:

INSERT INTO attendance (`team`,`event`,`year`) VALUES ('$team','$event','$year');

Everything looks fine (to my eye), but the year keeps returning as 0000 in the database even though the script prints 2012 when debugging.

My code is as follows:

// from shared parent script

$year = (date('m') < 9) ? date('Y') : date('Y')+1;

// attendance.php - file with code in question

<?php
header("Refresh: 43200;"); // refresh every 12 hours
ob_start();

echo "<p>Filling event rosters for the {$year} season.</p>"; ob_flush(); flush();

function getTeamList($event) {
    echo "<h3>Event '{$event}':</h3>"; ob_flush(); flush();

    echo "Removing old entries... "; ob_flush(); flush();
    mysql_query("DELETE FROM attendance WHERE event='$event' AND year='$year'");

    echo "Loading list from FIRST TIMS... "; ob_flush(); flush();
    $page =
file_get_contents("https://my.usfirst.org/myarea/index.lasso?page=teamlist&event_type=FRC&event=$event&year=$year&sort_teams=number");
    $page = explode('<td nowrap>',$page);
    $page = implode('<td>',array_slice($page,'1'));
    if ($event == 'CMP') {
        $page2 =
file_get_contents("https://my.usfirst.org/myarea/index.lasso?page=teamlist&event_type=FRC&event=$event&year=$year&sort_teams=number&skip_teams=250");
        $page2 = explode('<td nowrap>',$page2);
        $page2 = implode('<td>',array_slice($page2,'1'));
        $page = '<html><body><center><table>
<tr>
<td>'.$page.' <tr bgcolor="#FFFFFF">
        <td>'.$page2;
    }
    $timsList = new DOMDocument;
    $timsList->loadHTML($page);
    $listings = $timsList->getElementsByTagName('a');

    echo "Adding all current entries... "; ob_flush(); flush();
    foreach ($listings as $listing) {
        if (is_numeric($listing->nodeValue)) {
            $team = $listing->nodeValue;
            $query = "INSERT INTO attendance (`team`,`event`,`year`) VALUES ('$team','$event','$year')";    // Build SQL query for events
            mysql_query($query);
        }
    }
    echo "Done."; ob_flush(); flush();
    if ($event == 'CMP') {
        $div = array('archimedes','curie','galileo','newton');
        foreach ($div as $division) {
            mysql_query("DELETE FROM attendance WHERE event='$division' AND year='$year'");
            $page =
file_get_contents("https://my.usfirst.org/myarea/index.lasso?page=teamlist&event_type=FRC&event=$event&division=$division&year=$year&sort=teamnum");
            $page = explode('<td nowrap>',$page);
            $page = implode('<td>',array_slice($page,'1'));
            $timsList = new DOMDocument;
            @$timsList->loadHTML($page);
            $listings = $timsList->getElementsByTagName('a');
            foreach ($listings as $listing) {
                if (is_numeric($listing->nodeValue)) {
                    $team = $listing->nodeValue;
                    $query  = "INSERT INTO attendance (`team`,`event`,`year`) VALUES ('$team','$division','$year')";    // Build SQL Query
for Divisions
                    mysql_query($query);
                }
            }
        }
    }
}


if (isset($_GET["event"])) {
    $event = strtoupper(mysql_real_escape_string($_GET["event"]));
    mysql_select_db("frc");
    getTeamList($event);
} else {
    mysql_select_db("frc_{$year}scouting");
    $events = mysql_query("SELECT id FROM event WHERE event.start >= NOW()") or die(mysql_error());
    mysql_select_db("frc");
    while ($row = mysql_fetch_array($events)) {
        $event = $row['id'];
        getTeamList($event);
    }
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:39:34+00:00Added an answer on June 15, 2026 at 3:39 pm

    What is the datatype of the year field in MYSQL? If its set as datetime field, then your date is not valid and it will return 0000 for the year. (Invalid dates are stored as 0000-00-00 00:00:00 in mysql datetime)

    You could alter the database field to require an INT to make it work. Another option is to send in the year as $year.’-01-01 01:01:01′ to store it as the januari first of the date. But considering thats a bogus year, why store the extra data? Just use INT.

    UPDATE:

    The code you show is correct. Nothing wrong with it. There must be something going on in the code you are not showing, or you are thinking you set everything like you said but havent.

    $mysqli = new mysqli(...);
    
    $team = 10;
    $event = 'Testing';
    $year = date('Y');
    $query = "INSERT INTO attendance (`team`,`event`,`year`) VALUES ('$team','$event','$year')";
    
    print $query;
    $mysqli->query($query);
    

    Works like a charm using the exact datetypes as you in mysql.

    UPDATE 2:

    You are using $year in a function, but didnt include global $year;

    function getTeamList($event) {
        global $year;
        //....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very rough workaround for 10 statements using a combination of 2
I have very simple window where I have 2 buttons - one for cancel,
Well I have a very rough version of gomoku working now. I'm using Jquery,
However, I am very new to django and lighttpd and have very rough idea
I have a column in one of my SQL tables that is of type
I have a database with the current coordinates of every online user. With a
i have very serious problem if any tech expert can help...thank you in advance..
I have very simple piece of code. The goal is when i input four-digit
I have very very big html page/data. I need to fetch data under h1
I have very strange problem while I am submitting a practice problem on codechef.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.