-
Posts
376 -
Joined
-
Last visited
Posts posted by monkeypaw201
-
-
-
Couldn't you use a cron job to run that script every 15 minutes?
Yes, It is a cron job... but the problem is that right now when it runs, it deletes EVERYTHING, not just old data..
-
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?
-
Just embed bigdump
-
URL Includes usually indicates you are trying to use a URL, ie http://mysite.com/path. If you just include the filename only, you shouldn't get that error.
Not necessarily, it might assume that since its relative it would input the URL automatically ???
-
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\pearIf 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
-
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
-
THey probably have the url SSI disabled.. thats what happened to me.. check the PHP.INI
-
I assume there is a way to do something like:
INSERT INTO `table`, `column` = ''value"But i can't find the syntax anywhere..
I know the usual method is
INSERT INTO `table` VALUES('value')but i need to do it the first way
-
<?php
$ncustid = ($_GET['ncvx']) ? 0 : $_GET['ncvx'];
?>
Just as good.
I hate people who use isset and empty.
Somtimes, the simplest ways are the best (BTW don't diss just because you code differently)
-
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; }
-
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..
-
No, try this:
<?php if (isset($_GET['ncvx'])) { $ncustid = 0; }else{ $ncustid = $_GET['ncvx']; } ?>
I assume, you want to check if its passed in the URL?
-
I have encountered when things get finicky like that, leave the javascript OUTSIDE the PHP and put the PHP INSIDE the javascript
-
Yes, but using a CMS kind of takes away from what they hired you for ... you are then standardizing the entire internet (eventually) and there would be no "true" uniqueness..
They could just install it themselves at that point..
-
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; } }
-
Warning: implode() [function.implode]: Invalid arguments passed in clients.php on line 68
-
$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..
-
Notice: Undefined offset: 1 in clients.php on line 63
did I post the array incorrectly?
-
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"
-
$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.. ) any suggestions?
-
Never mind
-
If this is for a cronjob, use this instead
/usr/bin/php /path/to/myscript.php
-
Ok, well I added a placeholder column and it seems to be running smoothly now..
Thanks a lot to everyone!
--scampers off to donate--
$url
in PHP Coding Help
Posted
How about a .htaccess Permanent Re-Direct?