Jump to content

The Little Guy

Members
  • Posts

    6,675
  • Joined

  • Last visited

Posts posted by The Little Guy

  1. Here is what I came up with, but I don't know if it is good or not:

     

    function validDate(y, m, d){
    y = parseInt(y);
    m = parseInt(m);
    d = parseInt(d);
    ld = new Date(y, m, 0);
    lastDate = ld.getDate();
    date = new Date(y, m, d);
    if(y != date.getFullYear())
    	return false;
    if(m != date.getMonth())
    	return false;
    if(d != date.getDate() || date.getDate() > lastDate)
    	return false;
    return true;
    }

  2. JavaScript that executes what it is supposed to do, for example:

     

    <script>
    alert("hello");
    </script>

     

    will actually display an alert. I have ads that use JavaScript, I would like to add them to my RSS feed.

  3. To do this, you could do something like this(untested):

     

    <?php
    require_once "db_connection.php";
    require_once "MysqlClass.php";
    $database_name = "test";
    $new_database_name = "test2";
    
    $create_table = array();
    $tables = array();
    
    // User, password, host, database
    $db = new Mysql("user", "password", "localhost", "test");
    
    $db->query("show tables");
    while($row = $db->row()){
    $tables[] = $row["Tables_in_".$database_name];
    }
    foreach($tables as $table){
    $db->query("show create table $table");
    $row = $db->row();
    $create_table[$table] = $row["Create Table"];
    }
    
    // Create the new database and tables
    $db->query("create database $new_database_name");
    $db->query("use $new_database_name");
    foreach($create_table as $table => $create){
    $db->query($create);
    $db->query("alter table $table auto_increment = 0");
    }
    
    echo "\n\nNew Database Created!\n\n";
    ?>

  4. Only the InnoDB supports "Real" Foreign Keys:

    http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

     

    But you can have Foreign Keys in any other engine, but they won't be constant. With InnoDB, if you have a Primary Key and 10 tables that have a Foreign Key that points to the parent tables Primary Key, you can then update the primary key and all your foreign keys update along with it. In any other table you would have to update all the foreign keys manually.

     

    That is as much as I have read/heard about Foreign Keys.

  5. The only thing I have really made was something that did some bench marking.

     

    $d = new Debug(); // pass false to disable
    // Do some code
    $d->time();
    // Do some code
    $d->time();
    // Do some code
    $d->time();
    // Do some code
    $d->time();
    // Do some code
    $d->time();
    

     

    every time you called the time() method it would echo something like this:

     

    0.0282020983 seconds at line 2 in file /home/www/index.php
    0.0282020983 seconds at line 10 in file /home/www/index.php
    0.1282020983 seconds at line 81 in file /home/www/index.php
    4.0282020983 seconds at line 120 in file /home/www/index.php
    4.0482020983 seconds at line 578 in file /home/www/index.php

     

    As you can see on the 4th call it jumps up to 4 seconds and is something you might want to take a look at. If you were to place the $d->time() in an included file, it would say that file's name and the line in that file. I don't know if there is a better way to do this, but It has allowed me to pin point slow sections with in code after loops, MySQL queries, or any other constructs/functions/methods.

  6. We use git.

     

    The live site doesn't have git on it yet, but our beta one does. We are building a new phpsnips, and we have our beta on beta.phpsnips.com which has git, then we also have a personal copy of the website so we can run it on our personal computers too, then when we like what we have done we commit our changes to the beta. Once the beta is all complete, we will add git to the live site, and download the repository to the live site. This process will take less than 30 seconds. Once the live is the same as the beta we can work on our beta and push to the remote repository hundreds of times, then once there is a new feature ready to go live we will pull from the remote again on the live site and the new stuff will be live almost instantly!

     

    git is a fun and useful tool you should look into if you don't use it.

  7. no, that is the time the file was modified on the server, I want something that gives me when the file was last downloaded or something like that.

     

    I have this:

     

    header("Cache-Control: private, max-age=10800, pre-check=10800");
    header("Pragma: private");
    // Set to expire in 2 days
    header("Expires: " . date(DATE_RFC822,strtotime(" 2 day")));
    if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
      // if the browser has a cached version of this image, send 304
      header('Last-Modified: '.$_SERVER['HTTP_IF_MODIFIED_SINCE'],true,304);
      exit;
    }

     

    But it only seems to work on Apache.

  8. I need to know when a file was last modified to see if the browser has an updated cached version, if the browser does use its cache otherwise get the most current version.

     

    How can I do this?

  9. I am trying to get the top 10 most popular searches from my database, I have the following:

     

    select *, count(*) c FROM searches group by search_query order by c desc

     

    This will get the top ten, but it will also get values for people that searched for the same thing 2+ times. So if 2 people search for "Monkey", and one person searches for it 5 times and the other searches for that 3 times, it should show it was searched for 2 times.

     

    I am not sure how to format that query....

     

     

    mysql> explain searches;
    +--------------+------------------+------+-----+-------------------+----------------+
    | Field        | Type             | Null | Key | Default           | Extra          |
    +--------------+------------------+------+-----+-------------------+----------------+
    | search_id    | int(10) unsigned | NO   | PRI | NULL              | auto_increment |
    | ip           | int(10) unsigned | YES  |     | NULL              |                |
    | search_query | varchar(100)     | YES  |     | NULL              |                |
    | search_date  | timestamp        | YES  |     | CURRENT_TIMESTAMP |                |
    +--------------+------------------+------+-----+-------------------+----------------+
    4 rows in set (0.00 sec)

     

  10. login to your web server via putty (Windows) or terminal (Linux/Mac).

     

    in your home dir

    cd ~

     

    Download the file

    wget http://wordpress.org/latest.zip

     

    next unzip the files to your webserver

    unzip latest.zip -d ~/www/mysite.com

  11. make 2 tables

     

    table 1: dictionary

      - dictionary_id

      - word

     

    table 2: definition

        - definition_id

        - dictionary_id

        - definition

     

    so in table 1 dictionary_id would be an auto_increment filed, but not it table 2 and you would match on those two columns, it would look like so:

     

    select * from dictionary dic left join definition def using(dictionary_id) where dic.word = "bat";

     

    you would then get this:

     

    +---------------+------+---------------+---------------+----------------------------------------+
    | dictionary_id | word | definition_id | dictionary_id | definition                             |
    +---------------+------+---------------+---------------+----------------------------------------+
    | 1             | bat  | 1             | 1             | an animal with wings                   |
    | 1             | bat  | 2             | 1             | an instrument used by baseball players |
    +---------------+------+---------------+---------------+----------------------------------------+

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.