"YEAR problem nearly there"

We pass a parameter of a year value ($row[‘tourn_year’]) to the end of a URL as follows

      href="aa_tourn_index_history.php?tourn_year=<?php echo $row_tyear['tourn_year']; ?>"><?php echo $row_tyear['tourn_year']; ?></a></td></tr>
    <?php } while ($row_tyear = mysql_fetch_assoc($tyear)); ?>

mysql_free_result($tourn1);
mysql_free_result($tourn2);
mysql_free_result($tyear);
mysql_free_result($tourn_closed);
?>

So if 2020 is passed aa_tourn_index_history.php should display a year of 2020 and all events in that database with a tourn_year value of 2020

However it is showing a page stating it is 2021 (below)

Also the event listed actually has a year value of 2020 not 2021 as displayed.

I think this is a problem in the aa_tourn_index_history.php code that is invoked by the above call to it. Here is the aa_tourn_index_history.php code and wondered if you could help please as this is the last piece of a problem we have asked this group for help on (see my other post).

    <?php require_once('../Connections/connvbsa.php'); ?>
    <?php

    if (!isset($_SESSION)) {
      session_start();
    }

    $tourn_page = "http://www.vbsa.org.au/Admin_Tournaments/aa_tourn_index_history.php";
    $_SESSION['tourn_page'] = $tourn_page;

    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }

    if (isset($_GET['tourn_year'])) {
      $tourn_year = $_GET['tourn_year'];
    }

    mysql_select_db($database_connvbsa, $connvbsa);
    $query_tourn1 = "SELECT * FROM tournaments WHERE tourn_year = '$tourn_year' AND tourn_type='Snooker' ORDER BY tournaments.tourn_name";
    $tourn1 = mysql_query($query_tourn1, $connvbsa) or die(mysql_error());
    $row_tourn1 = mysql_fetch_assoc($tourn1);
    $totalRows_tourn1 = mysql_num_rows($tourn1);

    mysql_select_db($database_connvbsa, $connvbsa);
    $query_tourn2 = "SELECT * FROM tournaments WHERE tourn_year = '$tourn_year' AND tourn_type='Billiards' ORDER BY tournaments.tourn_name";
    $tourn2 = mysql_query($query_tourn2, $connvbsa) or die(mysql_error());
    $row_tourn2 = mysql_fetch_assoc($tourn2);
    $totalRows_tourn2 = mysql_num_rows($tourn2);
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="googlebot" content="noarchive,noindex,nofollow,nosnippet" />
    <meta name="robots" content="noarchive,noindex,nofollow" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>VBSA Administration</title>
    <meta name="googlebot" content="noarchive,noindex,nofollow,nosnippet" />
    <meta name="robots" content="noarchive,noindex,nofollow" />


    <script type="text/javascript" src="../Scripts/AC_RunActiveContent.js"></script>
    <script type="text/javascript" src="../Scripts/datepicker.js"></script>

    <link href="../Admin_xx_CSS/vbsa_DB.css" rel="stylesheet" type="text/css" />
    <link href="../Admin_xx_CSS/VBSA_db_links.css" rel="stylesheet" type="text/css" />
    <link href="../Admin_xx_CSS/Datepicker.css" rel="stylesheet" type="text/css" />

    </head>

    <body>
    <?php include '../admin_xx_includes/db_nav.php';?>
    <?php include '../admin_xx_includes/db_srch_treas.php';?>
    <table width="600" align="center">
      <tr>
        <td colspan="2" class="red_bold">&nbsp;</td>
      </tr>
      <tr>
        <td class="red_bold">  <?php $newDate = date("Y", strtotime($row_tourn1['tourn_year'])); echo $newDate; ?>
        Tournament History</td>
        <td align="right" class="greenbg"><a href="aa_tourn_index.php">Return to Tournaments</a></td>
      </tr>
    </table>
        <table align="center" cellpadding="5" cellspacing="5">
          <tr>
            <td colspan="13" align="center" class="red_bold" ><?php $newDate = date("Y", strtotime($row_tourn1['tourn_year'])); echo $newDate; ?> SNOOKER TOURNAMENTS</td>
          </tr>
          <tr>
            <td align="center">Tourn ID</td>
            <td align="left">Tournament Name</td>
            <td align="left">Year</td>
            <td align="left">Class</td>
            <td>Draw Type</td>
            <td align="center">View on site</td>
            <td>Type</td>
            <td align="center" nowrap="nowrap">Vic rank type</td>
            <td>Entries</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <?php do { ?>
            <tr>
              <td align="center"><?php echo $row_tourn1['tourn_id']; ?></td>
              <td align="left"><?php echo $row_tourn1['tourn_name']; ?></td>
              <td align="left"><?php $newDate = date("Y", strtotime($row_tourn1['tourn_year'])); echo $newDate; ?></td>
              <td align="left"><?php echo $row_tourn1['tourn_class']; ?></td>
              <td><?php echo $row_tourn1['tourn_draw']; ?></td>
              <td align="center"><?php echo $row_tourn1['site_visible']; ?></td>
              <td><?php echo $row_tourn1['tourn_type']; ?></td>
              <td align="center"><?php echo $row_tourn1['ranking_type']; ?></td>
              <td><?php echo $row_tourn1['status']; ?></td>
              <td><a href="tournament_detail.php?tourn_id=<?php echo $row_tourn1['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>"><img src="../Admin_Images/detail.fw.png" width="20" height="20" title="View all entries" /></a></td>
              <td><a href="user_files/tournament_edit.php?tourn_id=<?php echo $row_tourn1['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>"><img src="../Admin_Images/edit_butt.png" width="20" height="20" title="Edit tournament details" /></a></td>
              <td class="page"><a href="user_files/player_edit_all.php?tourn_id=<?php echo $row_tourn1['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>">Edit All</a></td>
              <td><a href="x_fin_rep.php?tourn_id=<?php echo $row_tourn1['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>"><img src="../Admin_Images/fin_butt.png" width="20" height="20" title="View tournament financials" /></a></td>
            </tr>
            <?php } while ($row_tourn1 = mysql_fetch_assoc($tourn1)); ?>
        </table>
    <table align="center" cellpadding="5" cellspacing="5">
          <tr>
            <td colspan="13" align="center" class="red_bold" ><?php $newDate = date("Y", strtotime($row_tourn2['tourn_year'])); echo $newDate; ?> BILLIARDS TOURNAMENTS</td>
          </tr>
          <tr>
            <td align="center">Tourn ID</td>
            <td align="left">Tournament Name</td>
            <td align="left">Year</td>
            <td align="left">Class</td>
            <td>Draw Type</td>
            <td align="center">View on site</td>
            <td>Type</td>
            <td align="center" nowrap="nowrap">Vic rank type</td>
            <td>Entries</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <?php do { ?>
          <tr>
            <td align="center"><?php echo $row_tourn2['tourn_id']; ?></td>
            <td align="left"><?php echo $row_tourn2['tourn_name']; ?></td>
            <td align="left"><?php $newDate = date("Y", strtotime($row_tourn2['tourn_year'])); echo $newDate; ?></td>
            <td align="left"><?php echo $row_tourn2['tourn_class']; ?></td>
            <td><?php echo $row_tourn2['tourn_draw']; ?></td>
            <td align="center"><?php echo $row_tourn2['site_visible']; ?></td>
            <td><?php echo $row_tourn2['tourn_type']; ?></td>
            <td align="center"><?php echo $row_tourn2['ranking_type']; ?></td>
            <td><?php echo $row_tourn2['status']; ?></td>
            <td><a href="tournament_detail.php?tourn_id=<?php echo $row_tourn2['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>"><img src="../Admin_Images/detail.fw.png" width="20" height="20" title="View all entries" /></a></td>
            <td><a href="user_files/tournament_edit.php?tourn_id=<?php echo $row_tourn2['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>"><img src="../Admin_Images/edit_butt.png" width="20" height="20" title="Edit tournament details" /></a></td>
            <td class="page"><a href="user_files/player_edit_all.php?tourn_id=<?php echo $row_tourn2['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>">Edit All</a></td>
            <td><a href="x_fin_rep.php?tourn_id=<?php echo $row_tourn2['tourn_id']; ?>&tourn_year=<?php echo $tourn_year; ?>"><img src="../Admin_Images/fin_butt.png" width="20" height="20" title="View tournament financials" /></a></td>
          </tr>
          <?php } while ($row_tourn2 = mysql_fetch_assoc($tourn2)); ?> 
    </table>
    <p>&nbsp;</p>
    </body>
    </html>
    <?php
    mysql_free_result($tourn1);

    mysql_free_result($tourn2);
    ?>

You need to do a direct dump or print_r() on the variable just a line above where you are doing the actual mysqli query to confirm what value you are actually receiving whether its 2020 or 2021

it’s one of the 2 issues either wrong value being passed , or a formatting issue in the mysql query

if need urgent help etc i can teamviewer and sort it out for a few bux etc…

Well, first, MySQL is outdated, not secure and also not used by any programmer. You must update to either MySQLi or PDO. The current favorite is PDO. Both of these are simple to update your code to.

Next, you did not tell us if the “tourn_year” format in the database. Is it stored as it should be as a date or datetime field? Or was it stored just as a string. If a string, you need to pass it using quotes around it. If an interger, then no quotes are needed.

Next, if you GET the year, it should have be already formatted correctly from the previous page. But, if not, you can use date_function or in the query itself, the MYSQL date_function to convert the date to the format you want to use it in. It sounds like the date is not being stored in the database correctly to start with.

Lastly, typing is not needed if the data was set up correctly. ALL PHP variables have the type built into them. Therefore you only need to use switch for types if you do not know what is passed to it. You, as the programmer, should know what the data is when it is passed forward and therefore already know the type. Meaning that you are using a switch to cast the value which should not be needed to do. Doubt that will make sense, but, it is not needed.

One further note. The first step in any programming project is to design the data correctly and design the database correctly to house this data. If you have a tournament date, it is normally stored in a DATE or DATETIME filed. One is with just the date, one includes the time of the tournament start. Once in this format, the standard date-time functions can be used to format it. You do not need to store the year separately since there is a function to pull out just the year if needed. This makes queries, searches, etc, much easier than attempting to manipulate the raw data.

Hope these notes help! Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service