Jump to content

monkeypaw201

Members
  • Posts

    376
  • Joined

  • Last visited

Posts posted by monkeypaw201

  1. So, I have a database and I would like to "flush" it every 15 minutes and remove any data older than 15 minutes.

     

    The code I am using right now removes everything even If its just a few minutes old. The column `last_update` is formatted using time()

     

    <?php
    #Connect to database
    $con = mysql_connect("localhost","user","pass");
    if (!$con)
     {
     die('Could not connect: ' . mysql_error());
     }
    
    #Select database
    mysql_select_db("database", $con);
    
    #Declare Flush Timestamp
    $timestamp = time();
    
    #Cycle Through and remove excess flights
    $flush = mysql_query("SELECT * FROM `active_flights`");
    while($row_flush = mysql_fetch_array($flush))
    {
    
    #Generate Timeout Timestamp
    $timeflush = $row_flush['last_update'] + 900;
    
    if($timeflush > $timestamp)
    {
    
    	mysql_query("DELETE FROM `active_flights` WHERE `id` = '$row_flush[id]' LIMIT 1");
    
    	mysql_query("DELETE FROM `active_flights_archive` WHERE `archive_id` = '$row_flush[archive_id]'");
    
    }
    
    }
    

     

    Any suggestions?

  2. THey probably have the url SSI disabled.. thats what happened to me.. check the PHP.INI

     

    Cheers, I am looking at it now...a little lost?? What exactly am I looking for??

     

    Also I have just noticed this....

     

    include_path - .;C:\php5\pear

     

    If that means anything? ???

     

    Have them enable URL includes

     

    Sounds like you are trying to include a page that is not on your site.

     

    Revraz,  if you notice the error:

     

    URL file-access is disabled in the server configuration

     

    Its a configuration blimp

  3. Is there a way to convert array to string? I'm not sure thats what I need, but something isn't working.. what step did i overlook?

     

    <?php
    #Link files into variables
    $vatsim_file = file($vatsim);
    $metacraft_file = file($metacraft);
    $fsproshop_file = file($fsproshop);
    
    #Get the last UPDATE variable
    $vatsim_time = substr($vatsim_file,2543,14);
    $metacraft_time = substr($metacraft_file,2543,14);
    $fsproshop_time = substr($fsproshop_file,2543,14);
    ?>
    

     

    Outputs:

     

    Notice: Array to string conversion in /incoming.php on line 23

     

    Notice: Array to string conversion in /incoming.php on line 24

     

    Notice: Array to string conversion in /incoming.php on line 25

  4. Hi monkeypaw,

     

    yes, you are correct.  I want to check for the existence of the variable in the URL just as you describe.

     

    Problem is, the function you wrote for some reason does not return the value if it does exist in the URL unless I add this after your code like this... which defeats the purpose of course :-)

     

    if (isset($_GET['ncvx']))

    {

    $ncustid = 0;

    }else{

    $ncustid = $_GET['ncvx'];

    }

    $ncustid = $_GET['ncvx'];

     

     

    it's as though the first part works correctly but it ignores the section AFTER the else even if there IS a value in the URL

     

    oops, my mistake! i reversed things..

     

    this should work:

     

    if (isset($_GET['ncvx']))
    {
    $ncustid = $_GET['ncvx'];
    }else{
    $ncustid = 0;
    }

  5. Thanks for the kwik help cdog & monkeypaw !

     

    cdog, i get an error with your code  :-(

     

    Monkeypaw, with your code, the error is gone, but the value does not seem to be returned?

     

    any suggestions ?

     

    thanks !

     

     

     

    I assume, you want to check if the variable ncvx is passed in the URL?

     

    (ie http://my.domain.com/page.php?ncvx=something)

     

    if so, try this:

    <?php
    if(isset($_GET['ncvx']))
    {
    $ncustid = 0;
    }else{
    $ncustid = $_GET['ncvx'];
    }
    ?>

     

    otherwise, please elaborate..

  6. ok, lemme start over, so we dont get confused...

     

    This script will:

    * Import a data file, and cut out the context we want

    * Separate each line, and feed each one into the loop

    * Load each line and seperate all the datapoints and insert into a database (if `cid` already exists in the database, simply update the current row..

     

    $file = 'data.txt';
    $start = '!CLIENTS:';
    $end = ';';
    
    # Put file to an array
    $lines = file( $file );
    
    # Set up placeholders
    $loop = TRUE;
    $capture = FALSE;
    $filtered = array();
    
    # Loop through lines, until we've found $end
    for( $i = 0, $count = count($lines); $i < $count && $loop === TRUE; $i++ ) {
    
       # Check to see if capturing has been turned on
       if ( $capture === TRUE ) {
           # Check to see if this is the endline
           if ( strpos($lines[$i], $end) === 0 )
               # End the loop
               $loop = FALSE;
           else
               # Explode and add to filtered results
               $filtered[] = explode( ':', trim($lines[$i] ) );
       }
       # Check to see if this is the starting line
       elseif ( strpos($lines[$i], $start) === 0 )
           # Turn on capturing
           $capture = TRUE;
    
    } 
    
    $columns = array('callsign', 'cid', 'realname', 'clienttype', 'frequency', 'latitude', 'longitude', 'altitude', 'groundspeed', 'planned_aircraft', 'planned_tascruise', 'planned_depairport', 'planned_altitude', 'planned_destairport', 'server', 'protrevision', 'rating', 'transponder', 'facilitytype', 'visualrange', 'planned_revision', 'planned_flighttype', 'planned_deptime', 'planned_actdeptime', 'planned_hrsenroute', 'planned_minenroute', 'planned_hrsfuel', 'planned_minfuel', 'planned_altairport', 'planned_remarks', 'planned_route', 'planned_depairport_lat', 'planned_depairport_lon', 'planned_destairport_lat', 'planned_destairport_lon', 'atis_message', 'time_last_atis_recieved', 'time_logon', 'heading', 'QNH_iHg', 'QNH_Mb','placeholder');
    
    $values = array();
    
    foreach( $filtered as $filter ) {
    
       if ( count($filter) != count($columns) ) {
           die( '
               Column counts did not match. MySQL expects ' .count($columns). '
    columns and 
               your data is giving it ' .count($filter). ' columns.
           ');
       }
    
       # Sanitize individual rows
              //Code removed, no need to sanitize single elements when we need to sanitize it all at once to get the single quotes in the implode escaped as well
    
       # Format and implode
       $values = mysql_real_escape_string( "('" . implode( "', '", $filter ) . "')" ); // Line messy looking, might consider rewriting
    
       $result = mysql_query("SELECT * FROM `clients` WHERE `cid` = '$values'")or die(mysql_error());
       $row = mysql_fetch_array($result);
       $count = mysql_num_rows($result);
    
       if($count == 0)
       {
       $q = "INSERT INTO `clients` (`" . implode( '`, `', $columns ) . "`) VALUES " . implode( ', ', $values );
       echo $q;
       }else{
       $q = "UPDATE `clients` SET" . $row['cid'];
       echo $q;
       }
    
    }
    

  7. $values = array();
    
    foreach( $filtered as $filter ) {
    
        if ( count($filter) != count($columns) ) {
            die( '
                Column counts did not match. MySQL expects ' .count($columns). '
    columns and 
                your data is giving it ' .count($filter). ' columns.
            ');
        }
    
        # Sanitize individual rows
        foreach ( $filter as $key => $val )
            $filter[$key] = mysql_real_escape_string( $val );
        # Format and implode
        $values[] = "('" . implode( "', '", $filter ) . "')";
    
        $result = mysql_query("SELECT * FROM `clients` WHERE `cid` = '$values[1]'")or die(mysql_error());
    echo $filtered[1];
        $row = mysql_fetch_array($result);
        $count = mysql_num_rows($result);
    
        if($count == 0)
        {
        $q = "INSERT INTO `clients` (`" . implode( '`, `', $columns ) . "`) VALUES " . implode( ', ', $values );
        echo $q;
        }else{
        $q = "UPDATE `clients` SET" . $row['cid'];
        echo $q;
        }
    
    }

     

    That should cover all the releveant code.. i know the $q UPDATE isn't done.. im just trying to see if it works..

  8. Personally speaking, I try to keep my database structure very similar and have a repository or scripts i made ahead of time, so its just a bit of copy/paste and modify a couple minor things...

     

    It helps because like you mentioned alot of websites require the standard "stuff"

  9.     $result = mysql_query("SELECT * FROM `clients` WHERE `cid` = '$values[0]'");
        $count = mysql_num_rows($result);

     

    Whenever I run that it throws the error:

     

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /clients.php on line 64

     

    I have tried everyhing i know.. bit its starting to just piss me off more than anything... before I throw my computer out the window (again.. :D) any suggestions?

×
×
  • 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.