php-general Digest 25 May 2008 01:40:48 -0000 Issue 5477
Topics (messages 274658 through 274671):
recursive function
274658 by: Manuel Pérez López
274660 by: Per Jessen
which costs more ?
274659 by: Feris
274664 by: Larry Garfield
274665 by: Robert Cummings
274668 by: Larry Garfield
274669 by: Feris
Re: A Little Something.
274661 by: Michelle Konzack
Zend Extension
274662 by: Ðавел ÐанÑлов
274663 by: Ðавел ÐанÑлов
Re: echo returnArray()['a']; // workaround
274666 by: Nitsan Bin-Nun
array recursion from database rows
274667 by: Bob
274670 by: Bastien Koert
274671 by: Chris W
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 ---
Hello everyone:
Is it possible to do recursive this function?
I can write it so linear. But only a finite number of loops.
Thanks.
Manuel Perez
This is:
function ($field, $arr_secuence_reverse)
{
if (count($arr_secuence_reverse) == 1)
{
return
getPrimaryKey4Field($field,$arr_secuence_reverse[0],NULL);
}
if (count($arr_secuence_reverse) == 2)
{
$sel2 = select($arr_secuence_reverse[0],"pk as
pk_current",NULL,$arr_secuence_reverse[1],"pk as pk_next",NULL);
foreach ($sel2 as $n2=>$v2)
{
$res[$v2['pk_current']] =
getPrimaryKey4Field($field,$arr_secuence_reverse[1],'fk_'.$arr_secuence_reverse[0]."='".$v2['pk_current']."'");
}
}
if (count($arr_secuence_reverse) == 3)
{
$sel3 = select($arr_secuence_reverse[0],"pk as
pk_current",NULL,$arr_secuence_reverse[1],"pk as pk_next",NULL);
foreach ($sel3 as $n3=>$v3)
{
$res[ $v3['pk_current'] ][ $v3['pk_next'] ] =
getPrimaryKey4Field($field,$arr_secuence_reverse[2],'fk_'.$arr_secuence_reverse[1]."='".$v3['pk_next']."'");
}
}
if (count($arr_secuence_reverse) == 4)
{
$sel4 = select($arr_secuence_reverse[0],"pk as
pk_current",NULL,$arr_secuence_reverse[1],"pk as pk_next",NULL);
foreach ($sel4 as $n4=>$v4)
{
$sel5 = select($arr_secuence_reverse[1],"pk as
pk_current",NULL,$arr_secuence_reverse[2],"pk as pk_next",NULL);
foreach ($sel5 as $n5=>$v5)
{
$res[ $v4['pk_current'] ][ $v4['pk_next'] ][
$v5['pk_current'] ] =
getPrimaryKey4Field($field,$arr_secuence_reverse[3],'fk_'.$arr_secuence_reverse[2]."='".$v5['pk_current']."'");
}
}
}
if (count($arr_secuence_reverse) == 5)
{
$sel5 = select($arr_secuence_reverse[0],"pk as
pk_current",NULL,$arr_secuence_reverse[1],"pk as pk_next",NULL);
foreach ($sel5 as $n5=>$v5)
{
$sel6 = select($arr_secuence_reverse[1],"pk as
pk_current",NULL,$arr_secuence_reverse[2],"pk as pk_next",NULL);
foreach ($sel6 as $n6=>$v6)
{
$res[ $v5['pk_current'] ][ $v5['pk_next'] ][
$v6['pk_current'] ][ $v6['pk_next'] ] =
getPrimaryKey4Field($field,$arr_secuence_reverse[4],'fk_'.$arr_secuence_reverse[3]."='".$v6['pk_next']."'");
}
}
}
}
--- End Message ---
--- Begin Message ---
Manuel Pérez López wrote:
> Hello everyone:
>
> Is it possible to do recursive this function?
>
> I can write it so linear. But only a finite number of loops.
Please explain which problem you're trying to solve - it'll be easier to
determine whether your problem has a recursive solution or not.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
Hi All,
I need to decide whether to consume feeds from third party as web services
or just creating my own system with relational MySQL backend.
Question is, which actually cost more ? Parsing a moderate streaming XML or
creating a mysql connection ? As I read from some sources that creating
initial connection to mysql is very costly.
Thanks,
Feris
--- End Message ---
--- Begin Message ---
On Saturday 24 May 2008, Feris wrote:
> Hi All,
>
> I need to decide whether to consume feeds from third party as web services
> or just creating my own system with relational MySQL backend.
>
> Question is, which actually cost more ? Parsing a moderate streaming XML or
> creating a mysql connection ? As I read from some sources that creating
> initial connection to mysql is very costly.
>
> Thanks,
>
> Feris
For what definition of "third party"? The cost of connecting to a MySQL
database on the same network segment as the web server will be minuscule
compared to the cost of connecting to a server in another state. (MySQL
connections are actually very fast to set up in PHP; second only to SQLite, I
suspect.)
The cost of parsing the XML will be tiny compared to the network latency. IO
is always your most expensive operation. Caching locally (disk, local MySQL
DB, etc.) can help a great deal, depending on your data.
So the answer is "you've not given enough information to make an intelligent
recommendation". :-)
--
Larry Garfield AIM: LOLG42
[EMAIL PROTECTED] ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
--- End Message ---
--- Begin Message ---
On Sat, 2008-05-24 at 09:55 -0700, Feris wrote:
> Hi All,
>
> I need to decide whether to consume feeds from third party as web services
> or just creating my own system with relational MySQL backend.
>
> Question is, which actually cost more ? Parsing a moderate streaming XML or
> creating a mysql connection ? As I read from some sources that creating
> initial connection to mysql is very costly.
It is almost certainly going to cost more to connect to a remote web
service than to connect to a local MySQL database server. Depending on
the XML received, it is quite likely parsing that will be heavier than
the internal routines for processing the DB's response into an array.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
I'm assuming this was intended for the list, not for me directly. Grumble
grumble.
If you want to pull in data from Google web services, then either
1) You always want the newest version and you just have to eat the cost;
2) You don't always need the newest version and you can cache it locally in
some form or another that makes sense for your use case. Storing that cache
in a local MySQL or SQLite database is probably the easiest/fastest/most
common method.
3) You decide you don't need Google data in the first place.
Which you do depends on your use case. Enjoy.
On Saturday 24 May 2008, Feris wrote:
> Hi Larry,
>
> On Sat, May 24, 2008 at 10:52 AM, Larry Garfield <[EMAIL PROTECTED]>
>
> wrote:
> > For what definition of "third party"? The cost of connecting to a MySQL
> > database on the same network segment as the web server will be minuscule
> > compared to the cost of connecting to a server in another state. (MySQL
> > connections are actually very fast to set up in PHP; second only to
> > SQLite, I
> > suspect.)
>
> Actually, it is Google web services (Picasa, Google Docs, etc) which
> returned XML feeds. And I plan to use that in my shared hosting
> environment. And yes, although my host has a separate MySQL location but it
> is still in the same network segment.
>
> The cost of parsing the XML will be tiny compared to the network latency.
>
> > IO
> > is always your most expensive operation. Caching locally (disk, local
> > MySQL
> > DB, etc.) can help a great deal, depending on your data.
>
> I see. Then that will make me considering that a call to web service's
> streaming XML is very costly (network latency + parsing cost).
>
> That caching is unthinkable for me, but it will be a valuable suggestion
> for me to redesigning my application if I still need to use those Google
> web services.
>
> > So the answer is "you've not given enough information to make an
> > intelligent
> > recommendation". :-)
>
> Thank you for pointing me that and giving a general consideration on PHP
> performance ;)
>
> > --
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Regards,
>
> Feris
--
Larry Garfield AIM: LOLG42
[EMAIL PROTECTED] ICQ: 6817012
"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
--- End Message ---
--- Begin Message ---
Hi Larry,
On Sat, May 24, 2008 at 11:54 AM, Larry Garfield <[EMAIL PROTECTED]>
wrote:
> I'm assuming this was intended for the list, not for me directly. Grumble
> grumble.
I'm sorry for replying you privately, it is my gmail's default :(
> If you want to pull in data from Google web services, then either
>
> 1) You always want the newest version and you just have to eat the cost;
>
> 2) You don't always need the newest version and you can cache it locally in
> some form or another that makes sense for your use case. Storing that
> cache
> in a local MySQL or SQLite database is probably the easiest/fastest/most
> common method.
>
> 3) You decide you don't need Google data in the first place.
>
> Which you do depends on your use case. Enjoy.
>
>
Thank you for the suggestions. Really appreciate it :)
Regards,
Feris
--- End Message ---
--- Begin Message ---
Am 2008-05-22 19:46:29, schrieb Stut:
> On 22 May 2008, at 15:10, Michelle Konzack wrote:
> >Not realy right, because the Music-Industry try to enforce a
> >International Law which they permit to contact directly the
> >ISP's for informations about customers...
>
> "try". Yup, that's right *you* said try. They need a court order to
> get that information (which is what I said) and they always will. If
> they can show that they have reasonable cause to believe someone has
> broken the law then a court order will be forthcoming. I don't have a
> problem with that, and if you have nothing to hide neither should you.
> [IMHO]
IF they have success with the NEW anti-Piracy-Law, they do not more need
to go to a court to ask for it. They can go directly to the ISPs...
And since ISPs can not vrify legitim the stuff, it can be abused.
> >And as I have already sayed, if they get ONE time infos about
> >me, I am tracable worldwide with my Laptop which let me run
> >into heavy trouble.
>
> I can't really reach any conclusion from that statement other than
> that you're breaking the law. You might want to stop doing that - you
> might be able to relax.
I am working for the FRENCH Army...
...and I am tracable from "enemies" like the USA.
> Don't really see the relevance of that comment and my comment. Are you
> actually reading what I'm typing? Block it if you want, I don't give a
> rats behind, but (yes, back to the actual point I originally made)
> don't block half of it and then complain that it's causing errors.
WHY does a Webpage DEPEND on something like the urchinTracker() ?
> You are *anonymously* traceable. They still need a court order to
No, it is not, since the IP of my computer is known and if I send an
E-Mail to a mailinglist, Google archive the E-Mail some minutes later
and you can find it in its index...
So, if I go in the same time into the Web and urchinTracker() get my
IP, I am not more Anonym!
As I have already sayed...
Google HAS the resources to track ANY peoples
> connect that information to you personally, and they don't hand those
> out without just cause. Again, I suggest you stop breaking the law so
> you can relax a bit.
And even, if Google itself do not use the Infos... They are working
togehter with US-Security agencies like FBI, CIA, NSA and DIA.
It falls under the "Patriot Act" which give those agencies tte right to
keep peoples under surveillance...
> Reference please? *How* are they using it? Are they using it like any
> other individual or organisation would use it, or do they have an
> illegal arrangement with Google to get access to personal information?
> Just looking for more than your word, that's all.
There was for two years a thread about something where the CIA have
tried to take over the Google-Databases for some days to check "the
world" for terroisn and such... this was refused by Google and the
US Supremscourt.
Some weeks late they have offical claimed the now working legaly with
Google.
And since Google offert "commercial use" of there Database... Google is
now a mutant of a PMC (Private military Contractor)
> >Because most users care about there priacy?
>
> I assume you mean "most users don't care". If people cared about their
Ehm, yes right...
Thanks, Greetings and nice Day
Michelle Konzack
Systemadministrator
24V Electronic Engineer
Tamay Dogan Network
Debian GNU/Linux Consultant
--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack Apt. 917 ICQ #328449886
+49/177/9351947 50, rue de Soultz MSN LinuxMichi
+33/6/61925193 67100 Strasbourg/France IRC #Debian (irc.icq.com)
signature.pgp
Description: Digital signature
--- End Message ---
--- Begin Message ---
Please, help me: give me a link to manual for Zend Extension developing
(please don't give me a link for simple PHP extension - i interested in
writing simple encoder like Zend Encoder :))
...Sorry for my English :)
--- End Message ---
--- Begin Message ---
Please, help me: give me a link to manual for Zend Extension developing
(please don't give me a link for simple PHP extension - i interested in
writing simple encoder like Zend Encoder :))
....Sorry for my English :)
--- End Message ---
--- Begin Message ---
Nice trick, I will remember this one.
Thanks for sharing,
Nitsan
On 23/05/2008, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
>
> On Fri, Feb 29, 2008 at 12:16 AM, Nathan Nobbe <[EMAIL PROTECTED]>
> wrote:
>
> > wow, im going to have to stare at some of those and play around with them
> > as soon as im half awake :)
> >
> > of course i still like my solution ;) but im excited about the
> > experimentation and ideas that have been shared on this topic, very
> > interesting really!
>
>
> i added __set() to my original class, now i can do cool stuff, like this:
>
> $a = ArrayClass::simpleFactory(getArray())->{'a'} = 5;
>
> which allows retrieval of the array, and modification (or access) to a
> given
> member, in a single statement.
>
> <?php
> class ArrayClass {
> private $theArray = array();
>
> private function __construct($theArray) {
> $this->theArray = $theArray;
> }
>
> public static function simpleFactory($theArray) {
> return new self($theArray);
> }
>
> public function __get($member) {
> if(array_key_exists($this->theArray, $member)) {
> return $this->theArray[$member];
> }
> return null;
> }
>
> public function __set($member, $value) {
> $this->theArray[$member] = $value;
> }
> }
>
> function getArray() {
> return array(
> 'a' => 1,
> 'b' => 2
> );
> }
>
> $a = ArrayClass::simpleFactory(getArray())->{'a'} = 5;
> var_dump($a);
> ?>
>
> maybe boring to some (or many :D) but as the first time around, i just
> thought it was cool and id share.
>
> -nathan
>
--- End Message ---
--- Begin Message ---
Hi.
I have a database table I have created for navigation.
The table fields are uid, parent_id, menu_name.
Each entry is either a top level element with a parent_id of 0 or a child
which has a parent_id that relates to the parent uid.
What I am trying to do is recurse through a set of rows adding the
child(ren) of a parent to a multi-dimensional array.
Does anyone know how I can do this, I've tried (unsuccessfully) to traverse
the rows to create this array but I keep failing miserably.
This is probably very easy for the people on this list so I am hoping
someone could help me out.
Thanks in advance.
Cheers.
Bob
--- End Message ---
--- Begin Message ---
On 5/24/08, Bob <[EMAIL PROTECTED]> wrote:
>
> Hi.
>
> I have a database table I have created for navigation.
>
> The table fields are uid, parent_id, menu_name.
>
> Each entry is either a top level element with a parent_id of 0 or a child
> which has a parent_id that relates to the parent uid.
>
> What I am trying to do is recurse through a set of rows adding the
> child(ren) of a parent to a multi-dimensional array.
>
> Does anyone know how I can do this, I've tried (unsuccessfully) to traverse
> the rows to create this array but I keep failing miserably.
>
> This is probably very easy for the people on this list so I am hoping
> someone could help me out.
>
> Thanks in advance.
>
> Cheers.
>
> Bob
if you order your result set by record id and parent id
then your set should be much easier to loop thru, when you hit an empty
parent id field its a new parent and you could use the row id (or whaever)
as the key and then keep adding the children until you hit a new (empty)
parent id
--
>
> Bastien
>
> Cat, the other other white meat
--- End Message ---
--- Begin Message ---
Bob wrote:
Hi.
I have a database table I have created for navigation.
The table fields are uid, parent_id, menu_name.
Each entry is either a top level element with a parent_id of 0 or a child
which has a parent_id that relates to the parent uid.
What I am trying to do is recurse through a set of rows adding the
child(ren) of a parent to a multi-dimensional array.
Does anyone know how I can do this, I've tried (unsuccessfully) to traverse
the rows to create this array but I keep failing miserably.
This is probably very easy for the people on this list so I am hoping
someone could help me out.
I recently wrote a function to do just that. My data structure is a
little different than yours. My table is called menuitems and is
designed to store menu items for many different menus. But I do use the
same ParentID concept you described to link sub menus in. I just call
my function recessively. Here is a slightly simplified version of my
function. I replaced the standard html tags with [ and ] to avoid
stupid email clients trying to encode it as an html message.
function PrintMenu($MenuID, $ParentItemID)
{
$query = "SELECT * \n";
$query .= "FROM `menuitem` \n";
$query .= "WHERE `MenuID` = '$MenuID' AND `ParentItemID` =
'$ParentItemID' \n";
$query .= "ORDER BY `OrderBy` \n";
//print "[pre>$query[/pre>\n";
$result = mysql_query($query);
QueryErrorLog($result, $query, __FILE__, __LINE__, __FUNCTION__,
mysql_error(), mysql_errno(), 1);
if(mysql_num_rows($result) > 0){
print "[ul]\n";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
foreach($row as $TmpVar => $TmpValue){
$$TmpVar = $TmpValue;
}
print "[li][a href='$URL']$Title[/a][/li]\n";
PrintMenu($MenuID, $MenuItemID);
}
print "[/ul]\n";
}
}
--
Chris W
KE5GIX
"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"
Ham Radio Repeater Database.
http://hrrdb.com
--- End Message ---