php-general Digest 29 Jul 2006 12:50:08 -0000 Issue 4264
Topics (messages 239867 through 239876):
different value in array
239867 by: weetat
239869 by: Paul Novitski
239871 by: Paul Novitski
239872 by: John Wells
compare value in 2 multidimension array
239868 by: weetat
PAYPAL TRANSACTION.
239870 by: BBC
[Case Closed - Idiot Found Behind Keyboard] Re: [PHP] APC - problems with CLI &
odd return values from apc_clear_cache()
239873 by: Jochem Maas
Saving a dynamic file
239874 by: MIGUEL ANTONIO GUIRAO AGUILERA
COULD NOT RESEND HEADER..
239875 by: BBC
239876 by: John Wells
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hi all,
I have 2 array which populated from MYSQL as shown below :
My program will update status in the temporary table according to
compare of 2 arrays, for example from 2 array below:
in $temptablearr = there 3 elements
in $currenttablearr = there 2 elements
If value different betweeen elements in the $temptablearr and
$currenttablearr , the status is change to 'update'.
If value are same between $temptablearr and $currenttablearr , no
action taken.
If there are new elements in $temptablearr and not found in
$currenttablearr, the status is change to 'new'
If there are elements found in $currenttablearr and not found in
$temptablearr , the status is change to 'deleted'
Anyone have any ideas or suggestion how to do this ? Thanks for your help.
$temptablearr = array(0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
2 =>
array("chassis_serial_no"=>"8888",
"country"=>"Indonesia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws999"),
);
$currenttablearr = array( 0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1=>
array("chassis_serial_no"=>"1235",
"country"=>"Singapore",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
);
Below is my test code .
<?php
$temptablearr = array(0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
2 =>
array("chassis_serial_no"=>"8888",
"country"=>"Indonesia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws999"),
);
$currenttablearr = array( 0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1=>
array("chassis_serial_no"=>"1235",
"country"=>"Singapore",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
);
$compare = true;
foreach($temptablearr as $key => $val)
{
if($currenttablearr[$key] != $val) {
$compare = false;
}
if($compare === false) {
echo 'update status in table to update<br><br>';
}else
if($compare === true){
echo 'skip, do not shown in page.<br><br>';
}
}
?>
--- End Message ---
--- Begin Message ---
At 11:18 PM 7/28/2006, weetat wrote:
I have 2 array which populated from MYSQL as shown below :
My program will update status in the temporary table according to
compare of 2 arrays, for example from 2 array below:
in $temptablearr = there 3 elements
in $currenttablearr = there 2 elements
If value different betweeen elements in the $temptablearr and
$currenttablearr , the status is change to 'update'.
If value are same between $temptablearr and $currenttablearr ,
no action taken.
If there are new elements in $temptablearr and not found in
$currenttablearr, the status is change to 'new'
If there are elements found in $currenttablearr and not found in
$temptablearr , the status is change to 'deleted'
Anyone have any ideas or suggestion how to do this ? Thanks for your help.
...
$currenttablearr = array( 0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1=>
array("chassis_serial_no"=>"1235",
"country"=>"Singapore",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
);
...
$compare = true;
foreach($temptablearr as $key => $val)
{
if($currenttablearr[$key] != $val) {
$compare = false;
}
if($compare === false) {
echo 'update status in table to update<br><br>';
}else
if($compare === true){
echo 'skip, do not shown in page.<br><br>';
}
}
Weetat,
You might consider concatenating all the elements in each sub-array
to make the comparison logic simpler, e.g.:
foreach ($currenttablearr as $key => $subarray)
{
$comparisonArray[$key] = explode("_", $subarray);
}
This would result in:
$comparisonArray[0] == "1235_Malaysia_cd-12345_ws8950"
$comparisonArray[1] == "1235_Singapore_cd-890_ws1234"
If you do that for both arrays you're comparing then it requires less
complicated code to discover which values in one array don't exist in
the other.
Paul
--- End Message ---
--- Begin Message ---
At 12:20 AM 7/29/2006, Paul Novitski wrote:
You might consider concatenating all the elements in each sub-array
to make the comparison logic simpler, e.g.:
foreach ($currenttablearr as $key => $subarray)
{
$comparisonArray[$key] = explode("_", $subarray);
}
This would result in:
$comparisonArray[0] == "1235_Malaysia_cd-12345_ws8950"
$comparisonArray[1] == "1235_Singapore_cd-890_ws1234"
Sorry, of course I meant implode(), not explode()!
http://php.net/implode
Paul
--- End Message ---
--- Begin Message ---
Nice tip Paul.
Weetat, I'm a bit concerned about your data as I look at it, and think
the approach I mentioned before needs a rewrite:
Do you have a a "primary key" in your arrays/rows? Meaning, how can
you tell if the two arrays you're comparing are just plain
_different_, or simply out of synch? Is it your card_serial_no? or
card_model? Or another column (like 'id') that you're not passing?
The point is, you need to know which is your "primary key" column and
do your testing based on these.
Then I think your whole update/new/delete/skip process might require
two passes: One to handle the update/skip assignments, and another for
the new/delete assignments. Use a combo of array_intersect() and
array_diff() to help you figure out what needs what...
HTH,
John W
On 7/29/06, Paul Novitski <[EMAIL PROTECTED]> wrote:
At 12:20 AM 7/29/2006, Paul Novitski wrote:
>You might consider concatenating all the elements in each sub-array
>to make the comparison logic simpler, e.g.:
>
> foreach ($currenttablearr as $key => $subarray)
> {
> $comparisonArray[$key] = explode("_", $subarray);
> }
>
>This would result in:
>
> $comparisonArray[0] == "1235_Malaysia_cd-12345_ws8950"
> $comparisonArray[1] == "1235_Singapore_cd-890_ws1234"
Sorry, of course I meant implode(), not explode()!
http://php.net/implode
Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hi all ,
I have 2 multidimension array as shown below:
I need to compare all values in the 2 multidimension array where
there are any elements values updated or a new elements or be deleted.
Updated mean when value in $temptablearr element is different from
value in $currenttablearr element, update status to 'Updated'
New mean when value in $temptablearr element is not exists in
$currenttablearr , update status to 'New'
Deleted mean when value in $currenttablearr element is not exists in
$temptablearr elements, update status to 'Deleted'
If the value are the same in 2 array elements , update status to 'SKIP'
The result of comparing is array of data which "deleted","updated"
and "new" except "SKIP" status.
I have been trying many way to do compare in array unsuccessful.
Anybody have any ideas or suggestions how to solve the issue , your
help is much appreciated. Thanks
$temptablearr = array(0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
2 =>
array("chassis_serial_no"=>"8888",
"country"=>"Indonesia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws999"),
);
$currenttablearr = array( 0 =>
array("chassis_serial_no"=>"1235",
"country"=>"Malaysia",
"card_serial_no"=>"cd-12345",
"card_model"=>"ws8950"),
1=>
array("chassis_serial_no"=>"1235",
"country"=>"Singapore",
"card_serial_no"=>"cd-890",
"card_model"=>"ws1234"),
);
--- End Message ---
--- Begin Message ---
Hi list..
Please any one point me to the web which talk about making transaction with
paypal step by step. Some body offered me the source
code and tutorial but until know he or she didn't send me.
Best Regards
============BBC============
**o<0>o**
--- End Message ---
--- Begin Message ---
Jon Anderson wrote:
> Just replying to the list on this one 'cause I'm pretty sure you're on
> it. :-)
>
> AFAIK, with many caches the web server cache and CLI caches are
> exclusive to each process. The APC manual seems to suggest that the CLI
> cache is not connected to the web server cache:
>
> From: http://ca.php.net/manual/en/ref.apc.php
>
> apc.enable_cli *integer*
> <http://ca.php.net/manual/en/language.types.integer.php>
>
> Mostly for testing and debugging. Setting this enables APC for the
> CLI version of PHP. Normally you wouldn't want to create, populate
> and tear down the APC cache on every CLI request, but for various
> test scenarios it is handy to be able to enable APC for the CLI
> version of APC easily.
thanks, you are right - what I thought had been working all this time had not,
or atleast the code did work but it was clearing the cache belonging to the CLI,
which was a pointless act!
I'm an idiot.
but wanting to clear the webservers APC cache from a cmdline script doesn't seem
like such a stupid thing to want to do. but there is no nice way of doing it;
so now
I do this at the end of my cmdline script instead:
exec('apachectl -k graceful');
which sucks in so many ways it hurts .... but it does clear the APC cache :-/
>
>
>
> jon
>
> Jochem Maas wrote:
>> hi people,
>>
>> PHP version: 5.1.1 (last built: Dec 28 2005 16:03:22)
>> APC version: 3.8.10
>> Apache version: 2.0.54 (last built: Dec 29 2005 14:04:16)
>> OS: debian
>>
>> I have a script that runs via the cmdline, it's used to import/update
>> data
>> in a database, after the script is run the APC cache needs to be
>> cleared so that
>> that the new/updated data is visible on the website. to do this I call
>> a static
>> method of my cache management class which effectively performs the
>> following:
>>
>> apc_clear_cache();
>> apc_clear_cache("user");
>>
>> this used to work, but now it does not (atleast not on the cmdline;
>> calling the
>> above mentioned method via a webrequest still works). I have not
>> recently updated
>> php, apc or apache, neither have made any changes to the php.ini
>> configuration.
>> someone else may have updated the OS/system (and I can't rule out that .
>>
>> to test the problem I ran the following code at the cmdline:
>>
>> # php -r 'var_dump( ini_get("apc.enable_cli"),
>> apc_clear_cache(),
>> apc_clear_cache("user") );'
>>
>> this is the output I get:
>>
>> string(1) "1"
>> NULL
>> bool(true)
>>
>> so apc is enabled for the cli, cache clearance seems to work but when
>> I checking the output
>> of the apc.php file (shipped with the apc package) I see that nothing
>> has been cleared; performing
>> the same apc_clear_cache() calls (by way of pressing the buttons on
>> the page output by apc.php) via
>> the webserver module *does* clear the cache.
>>
>> it seems all of a sudden that the CLI and then apache SAPI are looking
>> at different caches -
>> running apc_cache_info() && apc_sma_info() on the commandline show
>> nothing in the cache whereas
>> viewing the stats produced by apc.php (via the webserver) shows plenty
>> of stuff in the cache (both
>> before and after running apc_cache_info() && apc_sma_info() on the
>> commandline)
>>
>> can anyone offer some help/idea/etc?
>>
>>
>> Another Thing:
>> ===========================================================================
>>
>> although the manual states that apc_clear_cache() should always return
>> a boolean
>> calling it calling the function without any args *always* returns
>> NULL. can anyone say whether
>> this is a bug or a documentation problem?
>>
>>
>> My APC ini settings (as defined in a seperate apc.ini):
>> ===========================================================================
>>
>>
>>
>> ; Enable APC extension module
>> extension = apc.so
>>
>> [APC]
>> apc.enabled = 1
>> apc.shm_segments = 2
>> apc.shm_size = 128
>> apc.optimization = 0
>> apc.num_files_hint = 2000 ; ?
>> apc.ttl = 180
>> apc.gc_ttl = 0
>> apc.slam_defense = 0
>> apc.file_update_protection = 0 ; 1
>> apc.cache_by_default = 1
>> apc.enable_cli = 1
>> apc.filters = -.*\.class\.php
>>
>> ; +\.tpl\.php,+.*\.interface\.php,+.*\.funcs\.php
>> ; +.*\.class\.php
>>
>> ;apc.max_file_size = 8M
>> apc.user_entries_hint = 0
>> apc.user_ttl = 0
>>
>> ; this fixes a bug that causes $_SERVER not to be defined on
>> 2nd/subsequent requests
>> auto_globals_jit = Off
>>
>>
>
--- End Message ---
--- Begin Message ---
Hi!!
I'm in the need of saving to a file a dynamic page that I generated from a PHP
script, taking data from a table!!
So far I have figured out two options:
1) Save the page as a XML document so it can be editable in a word processor
later. Do I have to write line by line until I'm done with the document?
2) Use a class to convert & save the dynamic page into a Word document.
Is there any other options available??
Regards
------------------------------------------------
MIGUEL GUIRAO AGUILERA
Logistica R8 - Telcel
Tel: (999) 960.7994
Este mensaje es exclusivamente para el uso de la persona o entidad a quien esta
dirigido; contiene informacion estrictamente confidencial y legalmente
protegida, cuya divulgacion es sancionada por la ley. Si el lector de este
mensaje no es a quien esta dirigido, ni se trata del empleado o agente
responsable de esta informacion, se le notifica por medio del presente, que su
reproduccion y distribucion, esta estrictamente prohibida. Si Usted recibio
este comunicado por error, favor de notificarlo inmediatamente al remitente y
destruir el mensaje. Todas las opiniones contenidas en este mail son propias
del autor del mensaje y no necesariamente coinciden con las de Radiomovil
Dipsa, S.A. de C.V. o alguna de sus empresas controladas, controladoras,
afiliadas y subsidiarias. Este mensaje intencionalmente no contiene acentos.
This message is for the sole use of the person or entity to whom it is being
sent. Therefore, it contains strictly confidential and legally protected
material whose disclosure is subject to penalty by law. If the person reading
this message is not the one to whom it is being sent and/or is not an employee
or the responsible agent for this information, this person is herein notified
that any unauthorized dissemination, distribution or copying of the materials
included in this facsimile is strictly prohibited. If you received this
document by mistake please notify immediately to the subscriber and destroy
the message. Any opinions contained in this e-mail are those of the author of
the message and do not necessarily coincide with those of Radiomovil Dipsa,
S.A. de C.V. or any of its control, controlled, affiliates and subsidiaries
companies. No part of this message or attachments may be used or reproduced in
any manner whatsoever.
--- End Message ---
--- Begin Message ---
Hi all.
I try to make a page which checks the entire database and folder content, which
able to delete all invalid data's in the folder and
warns the user if an invalid data found in database. However I found the bug
with 'header()'
The codes below are not able to resend header if it's already sent, I need your
advice:
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Fri, 04 June 1982 05:00:00 GMT"); // Date in the
past
header('Content-type: image/jpeg');
The error message: "could not resend header, header already sent in line.."
And I also attach the quote of data for any one whom interested (to make it
more advance), otherwise just leave it !
Best Regards
============BBC============
**o<0>o**
--- End Message ---
--- Begin Message ---
On 7/29/06, BBC <[EMAIL PROTECTED]> wrote:
The error message: "could not resend header, header already sent in line.."
It isn't a bug. What it's saying is completely accurate. You can
only send header information to the browser once. As soon as you
output *anything* (via echo/print), headers are sent. So if you
output something, and then try the header() functions, you'll get your
error.
Make sure that your header() calls occur before any output. Or you
can buffer and catch your output if you can't keep it from being spit
out before your header() calls.
HTH,
John W
--- End Message ---