Re: Help. Mad problem!
| From: | Hemp Cluster | Date: | Mon, 17 May 2004 11:09:16 +0000 |
| Subject: | Re: Help. Mad problem! | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-4499@lists.php.net to get a copy of this message | ||
Hy....
try this code i have modifid some parts and documentated it.......
else you try a reset after every foreach ( how i know you must do it !!! )
hope i could help you
regards
Jointy
[code]
<?php
/////////////////////////////////////////////////
// This script scans the contents of the nx //
// inbox for .u files, indicating a user has //
// logged in. The logon names are extracted //
// from the filenames and recorded into an //
// access database. The .u files used are then //
// deleted so they are not later duplicated in //
// the database. //
/////////////////////////////////////////////////
require('odbc.inc'); // include file for db connectivity
require('config.inc'); // include file for nx directory config
if ($handle = opendir($nx_inbox)) // set path for nx inbox
{
/////////////////////////////////////////////////////////////
// //
// Identify .u files //
// //
/////////////////////////////////////////////////////////////
$array_of_filenames = array();
while (false !== ($file = readdir($handle))) // readdir gets next
{
if($extension = substr(strrchr($file, "."), 1 )== 'U') // get file
extension
{ // only works if 1 char
// filename stored
// if no file given no key will created
// so is no file given the array is empty and count return "0"
if( !is_null($file) )
{
$array_of_filenames[] = $file; // populate the array with filenames
}
}
}
$count_of_filenames = count($array_of_filenames);
for($i=0;$i< $count_of_filenames;$i++)
{
echo $array_of_filenames[$i]."\n";
}
//////////////////////////////////////////////////////////
// Error handling. Script will exit here if no .U files //
// are present in the inbox. "Invalid argument" errors //
// will occur if we try to so things with non existent //
// files. //
//////////////////////////////////////////////////////////
// Now check are no
if( $count_of_filenames == 0 ) // if first in index is null
{// errors will occur if no .u files are found so...
echo "Error, no .u files found. Exiting!!!!";
exit(0); // terminate script here if no .u files found
}
////////////////////////////////////////////
// //
// extract login names //
// //
////////////////////////////////////////////
/*
foreach( $array_of_filenames as $key=>$value )
{
// ???? Whats that !!!! i didn't understand what you want to cause with this....
$pos = strrpos($array_of_filenames[$key] = $value, "_");
// !!! u let u give the pos of the value of (array_of_filenames) and at the same time you
set it again
// ?????? u set the same key with the same value ????? why that ???????
$array_of_logons[] = substr
($array_of_filenames[$key] = $value, 0, $pos); // returns logon name
// !!!!! and here again !!!!!!!
}
*/
// !!!!!!!!!!!!!!!!!!!!!! TRY This !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
$array_of_logons = array();
for( $i=0;$i<$count_of_filenames;$i++ )
{
$array_of_logons[] = substr( $array_of_filenames[$i] , 0 ,
strpos($array_of_filenames[$i],"_") );
}
////////////////////////////////////////////
// //
// Enter logged in users to the database //
// //
////////////////////////////////////////////
foreach($array_of_logons as $value)
{
odbc_exec($odbc, "INSERT INTO users (logged_in) VALUES
('".$value."')")
or die (odbc_errormsg()); // insert logged on users into the db
}
////////////////////////////////////////////
// //
// Delete .u files used //
// //
////////////////////////////////////////////
for( $i=0;$i<$count_of_filenames;$i++ )
{
unlink($nx_inbox.$array_of_filenames[$i]); // delete .u files used
}
unset($array_of_filenames,$count_of_filenames);
closedir(); // close the directory when finished
}
?>
[/code]
> Got a really odd problems. This script reads text files and inserts names into an Access
> database. For some reason it always misses 1 of the files if there are several files. Also if there
> is only 1 file it doesn't insert the data into the database but seems to think it does.
> Beenstaring at this for a while now and can't get it. Any help appreciated.
>
--
Jointy <bestmischmaker@web.de>
---------------------------------------------------------------------------------------------
Homepage: http://www.rt31x-tutorial.de
---------------------------------------------------------------------------------------------