Hi

dabaR.

I somehow did not see your reply.

Your solution looks interesting and maybe what I am looking for.

Will look into it. Thanks

    jamjam wrote:

    On the second point, I thought the only way to retrieve data from the database is to specify the relavant variables on url string.

    No, it is not. The query string has nothing to do with the database, other than what your script does with it. You are probably confusing "query string" with "database query".

      Let me explain my current setup.

      I am working on localhost with PHP and Mysql.

      When I type http://localhost/home/?date=01-06 into my browser,
      I can retrieve results from my database that match the dated specified in the query string.

      I want to setup a default page where I do not need to add the query string but still returns a result for the current day.

      I could use html redirects but this will involve updating that address everyday, not ideal.
      I want some dynamic way of doing this.

        Ya, my posts are put in a moderation queue to be approved since I just joined.

        Show the line of PHP that goes to the database currently, please.

          Hi

          Not sure about which line you mean so i decided to provide the whole script.
          This PHP will eventually will inserted into a html template.

          I created this with Dreamweaver CS4 by the way.

          <?php require_once('Connections/date.php'); ?>
          <?php require_once('../Connections/search_db.php'); ?>
          <?php
          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 (!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;
          }
          }

          mysql_select_db($database_date, $date);
          $query_rs84 = "SELECT Date, String FROM search";
          $rs84 = mysql_query($query_rs84, $listings) or die(mysql_error());
          $row_rs84 = mysql_fetch_assoc($rs84);
          $totalRows_rs84 = mysql_num_rows($rs84);

          $coldate_rs83 = "=1";
          if (isset($GET['date'])) {
          $coldate_rs83 = $
          GET['date'];
          }
          mysql_select_db($database_search_db, $search_db);
          $query_rs83 = sprintf("SELECT * FROM search WHERE Date = GetSQLValueString($coldate_rs83, "text"));
          $rs83 = mysql_query($query_rs83, $search_db) or die(mysql_error());
          $row_rs83 = mysql_fetch_assoc($rs83);
          $totalRows_rs83 = mysql_num_rows($rs83);
          ?>

            jamjam;10954070 wrote:
            $coldate_rs83 = "=1";
            if (isset($_GET['date'])) {
              $coldate_rs83 = $_GET['date'];
            }
            mysql_select_db($database_search_db, $search_db);
            $query_rs83 = sprintf("SELECT * FROM search WHERE Date = GetSQLValueString($coldate_rs83, "text"));
            

            That's the relevant piece. Even if you just change:

            $coldate_rs83 = "=1";
            

            to

            $coldate_rs83 = date('Y-m-d');
            

            That will probably do what you want. That will make the default date be today, whatever today is at the time the script runs.

              $query_rs83 = sprintf("SELECT * FROM search WHERE Date = GetSQLValueString($coldate_rs83, "text"));
              

              That has an uneven number of double quotes, so it likely does not compile. You will probably need

              $query_rs83 = sprintf("SELECT * FROM search WHERE Date = " .  GetSQLValueString($coldate_rs83, "text"));
              

                WOW. Thats cool.

                I edited the code when I pasted into the browser so properly deleted something that was already there. For you to spot something so small you must know what you are doing.

                I will try out your solution and report back

                Thanks again

                  jamjam;10954073 wrote:

                  WOW. Thats cool.
                  I edited the code when I pasted into the browser so properly deleted something that was already there. For you to spot something so small you must know what you are doing.

                  I'm a human compiler :-)

                    YES YES YES!!!!

                    It works.

                    I can't believe it. Such a simple solution yet so perfect.

                    The only thing I changed was the date format to dd-mm with no year specified.

                    Thanks man

                    I owe you bigtime .

                      :-)

                      Do you plan to run the site only for one year? You better incorporate the year if you intend to run it for longer than a year.

                        The site will contain TV Listings data after one year the data will be old and get overwritten with new data.
                        I could add the year but this will increase the data entry task so have decided to ommit it.

                          Write a Reply...