php-general Digest 22 Mar 2012 19:08:44 -0000 Issue 7739

Topics (messages 317172 through 317189):

Re: hello everybody
        317172 by: Midhun Girish
        317173 by: Michael Save

Re: Node.PHP
        317174 by: Michael Save

Re: Thinking out loud - a continuation...
        317175 by: Bastien
        317178 by: Jay Blanchard
        317179 by: Tedd Sperling
        317180 by: Jay Blanchard
        317181 by: Robert Cummings
        317182 by: Jay Blanchard
        317183 by: Robert Cummings
        317184 by: Robert Cummings
        317185 by: Jay Blanchard
        317186 by: Jay Blanchard
        317187 by: Robert Cummings
        317188 by: Jay Blanchard
        317189 by: Robert Cummings

Re: Got HTML5 History API + caching LICKED, I think, <grin>
        317176 by: rene7705
        317177 by: rene7705

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
I think this would be an ideal resource for beginners
http://www.w3schools.com/php/php_forms.asp. I used it when i began php. I
would suggest doing the entire course in there. Really helpful.

Regards
Midhun Girish



On Sun, Mar 18, 2012 at 10:05 PM, Jeremy Wei <shuimuqing...@gmail.com>wrote:

> you can read the content about form dealing in php manual:
> http://us.php.net/manual/en/tutorial.forms.php
>
> On Sun, Mar 18, 2012 at 7:34 PM, saeed ahmed <mycomputerbo...@gmail.com>
> wrote:
> > i am a full time warehouse worker and do not have time.i hardly can spend
> > 2/3 hours a week on internet(at work we do not use internet but only
> > computer)i am learning php and have xampp installed on my computer and i
> > think i am learning slowly slowly.i want ot ask one favor to someone,who
> is
> > capable of doing this small work.i have learned that when visitor fill a
> > form after visitor get message with his name.how this function is added
> and
> > where?
> >
> > can anyon give me a example like giving a example to a child of 10
> years.i
> > would like if someone explain me.
>
>
>
> --
> JeremyWei(魏志锋,字静之)
> Mob: 18914495716
> 新浪微博:@JeremyWei
> QQ: 327493482
> Home: www.weizhifeng.net
> Less is more
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
w3schools is not a good source.

http://w3fools.com/

On Thu, Mar 22, 2012 at 5:33 PM, Midhun Girish <midhungir...@gmail.com> wrote:
> I think this would be an ideal resource for beginners
> http://www.w3schools.com/php/php_forms.asp. I used it when i began php. I
> would suggest doing the entire course in there. Really helpful.
>
> Regards
> Midhun Girish
>
>
>
> On Sun, Mar 18, 2012 at 10:05 PM, Jeremy Wei <shuimuqing...@gmail.com>wrote:
>
>> you can read the content about form dealing in php manual:
>> http://us.php.net/manual/en/tutorial.forms.php
>>
>> On Sun, Mar 18, 2012 at 7:34 PM, saeed ahmed <mycomputerbo...@gmail.com>
>> wrote:
>> > i am a full time warehouse worker and do not have time.i hardly can spend
>> > 2/3 hours a week on internet(at work we do not use internet but only
>> > computer)i am learning php and have xampp installed on my computer and i
>> > think i am learning slowly slowly.i want ot ask one favor to someone,who
>> is
>> > capable of doing this small work.i have learned that when visitor fill a
>> > form after visitor get message with his name.how this function is added
>> and
>> > where?
>> >
>> > can anyon give me a example like giving a example to a child of 10
>> years.i
>> > would like if someone explain me.
>>
>>
>>
>> --
>> JeremyWei(魏志锋,字静之)
>> Mob: 18914495716
>> 新浪微博:@JeremyWei
>> QQ: 327493482
>> Home: www.weizhifeng.net
>> Less is more
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

--- End Message ---
--- Begin Message ---
Very nice!

I'll have a proper look at this in the morning, and I'll try it out
for myself. Looking forward to seeing more development on this.

Michael

On Thu, Mar 22, 2012 at 11:40 AM, Joseph Moniz <joseph.mo...@gmail.com> wrote:
> Hey,
>
> So i had my first Hackathon at work last week and my project was to
> prototype making a node.js clone using PHP instead of V8. So i
> snatched up libuv and joyent's HTTP parser and set off on a 24 hour
> coding spree to get something workable. By the time the sun was coming
> out the next morning the following code was working.
>
>    <?php
>
>    $http = new node_http();
>
>    $http->listen(8080, function($request, $response) {
>        $response->end("yay, super awesome response");
>    });
>
>    nodephp_run();
>
>    ?>
>
> The C code that powers it was whipped together really fast and is kind
> of hackish as a result. The code has some memory leaks that i haven't
> had time to fully track down yet. Some small portions of the code were
> borrowed from the phode project.
>
> In a naive benchmark on this simple server VS an equally simple server
> in node.js this implementation already out performs node.js in
> throughput by being able to serve just under 200% the amount of
> requests per second that node.js could. Take that with a grain of salt
> though because node.js has much more feature and is much more hardend
> from production use. I do believe the PHP binary will have some major
> performance gains over V8 as crossing the PHP <--> C barrier seems to
> be a much lighter operation then crossing the V8 <--> C++ barrier.
>
> Any help or feedback will be greatly appreciated. The projects source
> code can be found here: https://github.com/JosephMoniz/node.php
>
> - Joseph Moniz
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---

On 2012-03-21, at 2:39 PM, Jay Blanchard <jay.blanch...@sigmaphinothing.org> 
wrote:

> This is a continuation of the nested query thing I posted to the list a while 
> back. I was finally able to output a nested unordered array that worked out 
> well, but scope-creep has come in the door and I have to change gears.
> 
> I have a project where I have multiple queries and each query uses the 
> results from the previous query to get it's results. I need to do one of two 
> things, either out put a multidimensional array that I can use json_encode() 
> on or I have to format the output from the queries as a JSON string. The 
> resulting JSON will be used by a JavaScript widget and must be formed 
> correctly. I created the following array by hand:
> 
> $userList = array("John" => array(
>                     "email" => "j...@demo.com",
>                     "website" => "www.john.com",
>                     "age" => "22",
>                     "password" => "pass",
>                     "description" => array(
>                         "hair" => "blonde",
>                         "eyes" => "blue",
>                         "build" => "medium"
>                     )),
>                  "Anna" => array(
>                     "email" => "a...@demo.com",
>                     "website" => "www.anna.com",
>                     "age" => "24",
>                     "password" => "pass",
>                     "description" => array(
>                         "hair" => "brunette",
>                         "eyes" => "hazel",
>                         "build" => "petite"
>                         )
>                     ));  
> 
> I ran it through json_encode() and got the following output
> 
> {"John":{"email":"j...@demo.com","website":"www.john.com","age":"22","password":"pass","description":{"hair":"blonde","eyes":"blue","build":"medium"}},"Anna":{"email":"a...@demo.com","website":"www.anna.com","age":"24","password":"pass","description":{"hair":"brunette","eyes":"hazel","build":"petite"}}}
> 
> jslint.com verifies this as good JSON (although I thought there had to be 
> square brackets around child arrays).
> 
> If you were me would you just generate the JSON? If not what is he best way 
> to output an array that will nest properly for each subsequent query?
> 
> Thanks for any insight!
> 
> 
Would it not be easier to get the data from a view which has the tables joined? 
Then it would be one query and it's a simple matter to format the results into 
the multi dimensional array then json?

Bastien

--- End Message ---
--- Begin Message ---
[snip]
Would it not be easier to get the data from a view which has the tables joined? 
Then it would be one query and it's a simple matter to format the results into 
the multi dimensional array then json?
[/snip]

The data is all from one table. I'll write up a more thorough explanation in a 
little while.


--- End Message ---
--- Begin Message ---
On Mar 21, 2012, at 3:45 PM, Daniel Brown wrote:
> 
>    I would, yes, but that's not the point.  Is Anna single?  I'm
> ready to trade Debs in for a newer model.
> 
> -- 
> </Daniel P. Brown>

Ah... to be young again. But, on the other hand, they have so much to learn. :-)

Cheers,

tedd

_____________________
tedd.sperl...@gmail.com
http://sperling.com






--- End Message ---
--- Begin Message ---
[snip]
...stuff...
[/snip]

Here is the explanation for what I have done and what I am trying to do - (based on the customer's request).

A week or so ago I took a set of queries from one table and made them into an unordered list. This will be pseudo-code so that you get idea.

SELECT DISTINCT column1 FROM table
WHERE company = '1'

while($column1 = mysql_fetch_array($query1results)){
    SELECT DISTINCT column2 FROM table
    WHERE company = '1'
    AND column1 = $column1[0]

    while($column2 = mysql_fetch_array($query2results)){
        SELECT DISTINCT column3 FROM table
        WHERE company = '1'
        AND column2 = $column2[0]
    }
}

This continues for up to 14 columns of data. I'm not worried about the recursive data retrieval, I have that part and like I said - I can output a nested unordered list from it quite handily.

Now the customer wants JSON as the output. The JSON must reflect the children properly.

So I have two choices, a multidimensional array that I can use json_encode() on or output a string that ultimately forms the JSON. We have all agreed that doing an array would be the best thing but I cannot wrap my head around it.

If you have more questions fire away - I'd love to get this solved and off of my plate.
--- End Message ---
--- Begin Message ---
On 12-03-22 11:28 AM, Jay Blanchard wrote:
[snip]
...stuff...
[/snip]

Here is the explanation for what I have done and what I am trying to do
- (based on the customer's request).

A week or so ago I took a set of queries from one table and made them
into an unordered list. This will be pseudo-code so that you get idea.

SELECT DISTINCT column1 FROM table
WHERE company = '1'

while($column1 = mysql_fetch_array($query1results)){
      SELECT DISTINCT column2 FROM table
      WHERE company = '1'
      AND column1 = $column1[0]

      while($column2 = mysql_fetch_array($query2results)){
          SELECT DISTINCT column3 FROM table
          WHERE company = '1'
          AND column2 = $column2[0]
      }
}

This continues for up to 14 columns of data. I'm not worried about the
recursive data retrieval, I have that part and like I said - I can
output a nested unordered list from it quite handily.

Now the customer wants JSON as the output. The JSON must reflect the
children properly.

So I have two choices, a multidimensional array that I can use
json_encode() on or output a string that ultimately forms the JSON. We
have all agreed that doing an array would be the best thing but I cannot
wrap my head around it.

If you have more questions fire away - I'd love to get this solved and
off of my plate.

Fix this code... I've come across codebases that did this specific type of nested querying and it resulted in 10000 queries to the database on every page. Instead, create a layered approach:

    1. Select your root elements.
    2. Loop over in PHP and create an array of child IDs.
    3. Select the children from the database.
    4. Go to step 2.

This way you will only every perform "depth" number of queries.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
[snip]
Fix this code... I've come across codebases that did this specific type of nested querying and it resulted in 10000 queries to the database on every page. Instead, create a layered approach:

    1. Select your root elements.
    2. Loop over in PHP and create an array of child IDs.
    3. Select the children from the database.
    4. Go to step 2.

This way you will only every perform "depth" number of queries.
[/snip]

I see what you're saying but I don't know that this reduces the number of queries - it just handles them in a different order. How do I get to the output that I need?
--- End Message ---
--- Begin Message ---
On 12-03-22 11:58 AM, Jay Blanchard wrote:
[snip]
Fix this code... I've come across codebases that did this specific
type of nested querying and it resulted in 10000 queries to the
database on every page. Instead, create a layered approach:

     1. Select your root elements.
     2. Loop over in PHP and create an array of child IDs.
     3. Select the children from the database.
     4. Go to step 2.

This way you will only every perform "depth" number of queries.
[/snip]

I see what you're saying but I don't know that this reduces the number
of queries - it just handles them in a different order. How do I get to
the output that I need?

It definitely reduces the queries... your current method gets all the first level nodes in one query, then performs a query for every single parent node. Mine only performs a query for each level in the tree. If you have 5 nodes at the first level you will perform 6 queries. Mine will perform 2.

To generate the nesting structure at each level you track the level members. Something like the following (untested pseudoish):

<?php

$parents = query_for_first_level();
$root = &$parents;

while( $parents )
{
    $parentIds = array();
    foreach( $parents as $parent )
    {
        $parentIds[$parent['id']] = $parent['id'];
    }

    $children = query_for_children( $parentIds );
    foreach( $children as &$child )
    {
        $parents[$child['parentId']]['children'][] = &$child;
    }

    $parents = &$children;
}

$jsonData = JSON_encode( $root );

?>

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On 12-03-22 11:58 AM, Jay Blanchard wrote:
[snip]
Fix this code... I've come across codebases that did this specific
type of nested querying and it resulted in 10000 queries to the
database on every page. Instead, create a layered approach:

     1. Select your root elements.
     2. Loop over in PHP and create an array of parent IDs.
     3. Select the children from the database.
     4. Go to step 2.

This way you will only every perform "depth" number of queries.
[/snip]

I see what you're saying but I don't know that this reduces the number
of queries - it just handles them in a different order. How do I get to
the output that I need?

Sorry, I just realized I didn't make the optimization explicitly obvious... when I say "Select the children" I mean to select them using an IN( id1, id2, id3 ) clause instead of a query for each. This is why we build the array of parent IDs (also I wrote build an array of "child IDs", it should have read "parent IDs" and has been fixed above :).

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
[snip]
On 3/22/2012 11:17 AM, Robert Cummings wrote:
On 12-03-22 11:58 AM, Jay Blanchard wrote:
[snip]
Fix this code... I've come across codebases that did this specific
type of nested querying and it resulted in 10000 queries to the
database on every page. Instead, create a layered approach:

     1. Select your root elements.
     2. Loop over in PHP and create an array of child IDs.
     3. Select the children from the database.
     4. Go to step 2.

This way you will only every perform "depth" number of queries.
[/snip]

I see what you're saying but I don't know that this reduces the number
of queries - it just handles them in a different order. How do I get to
the output that I need?

It definitely reduces the queries... your current method gets all the first level nodes in one query, then performs a query for every single parent node. Mine only performs a query for each level in the tree. If you have 5 nodes at the first level you will perform 6 queries. Mine will perform 2.
[/snip]

How so? A query must be performed for each parent node to get its children.

                                 parent
                                       |
                child    child    child    child
                    |
grandchild grandchild


[snip]
To generate the nesting structure at each level you track the level members. Something like the following (untested pseudoish):

<?php

$parents = query_for_first_level();
$root = &$parents;

while( $parents )
{
    $parentIds = array();
    foreach( $parents as $parent )
    {
        $parentIds[$parent['id']] = $parent['id'];
    }

    $children = query_for_children( $parentIds );
    foreach( $children as &$child )
    {
        $parents[$child['parentId']]['children'][] = &$child;
    }

    $parents = &$children;
}

$jsonData = JSON_encode( $root );

?>
[/snip]

I'll try to apply this and see what I run into.

--- End Message ---
--- Begin Message ---
[snip]
Sorry, I just realized I didn't make the optimization explicitly obvious... when I say "Select the children" I mean to select them using an IN( id1, id2, id3 ) clause instead of a query for each. This is why we build the array of parent IDs (also I wrote build an array of "child IDs", it should have read "parent IDs" and has been fixed above :).
[/snip]

SELECT DISTINCT children FROM table WHERE column1 IN(id1, id2, id3....) ?

I am sure I am not following you now. Maybe I didn't explain clearly?

--- End Message ---
--- Begin Message ---
On 12-03-22 12:34 PM, Jay Blanchard wrote:
[snip]
Sorry, I just realized I didn't make the optimization explicitly
obvious... when I say "Select the children" I mean to select them
using an IN( id1, id2, id3 ) clause instead of a query for each. This
is why we build the array of parent IDs (also I wrote build an array
of "child IDs", it should have read "parent IDs" and has been fixed
above :).
[/snip]

SELECT DISTINCT children FROM table WHERE column1 IN(id1, id2, id3....) ?

I am sure I am not following you now. Maybe I didn't explain clearly?

What's the field for which you are selecting data? I've written this up as a parent/child relationship but it works for data/sub-data relationships also.

SELECT itemId, otherData FROM table WHERE "some condition";

SELECT itemId, subData FROM otherTable WHERE itemId IN (id1, id2, ...);

Then just link up the sub-data to the primary data in a loop and finally generate your JSON.

Does that clarify?

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On 3/22/2012 11:40 AM, Robert Cummings wrote:
On 12-03-22 12:34 PM, Jay Blanchard wrote:
[snip]
Sorry, I just realized I didn't make the optimization explicitly
obvious... when I say "Select the children" I mean to select them
using an IN( id1, id2, id3 ) clause instead of a query for each. This
is why we build the array of parent IDs (also I wrote build an array
of "child IDs", it should have read "parent IDs" and has been fixed
above :).
[/snip]

SELECT DISTINCT children FROM table WHERE column1 IN(id1, id2, id3....) ?

I am sure I am not following you now. Maybe I didn't explain clearly?

What's the field for which you are selecting data? I've written this up as a parent/child relationship but it works for data/sub-data relationships also.

SELECT itemId, otherData FROM table WHERE "some condition";

SELECT itemId, subData FROM otherTable WHERE itemId IN (id1, id2, ...);

Then just link up the sub-data to the primary data in a loop and finally generate your JSON.

Does that clarify?
[/snip]

I must confess that the raging sinus headache and my general confusion makes this really unclear for me today. Maybe I should just set it aside for a day or so. I am super dense today.

For each level I am selecting for each parent in the level above. Let's say that level 2 contains 8 people. Level 3 contains 14 people. Only some of the 14 belong to the 8 and must be associated properly. So how can I, with one query, associate level 3' 8th, 9th and 10th people with level 2's 6th person keeping in mind that the 9th person might also belong to level 2's 4th person.

Just link up the sub-data? Place this array into a child array of the parent array? Again I apologize - maybe I should push away and let the customer know that it'll be a couple of more days.
--- End Message ---
--- Begin Message ---
On 12-03-22 01:06 PM, Jay Blanchard wrote:
On 3/22/2012 11:40 AM, Robert Cummings wrote:
What's the field for which you are selecting data? I've written this
up as a parent/child relationship but it works for data/sub-data
relationships also.

SELECT itemId, otherData FROM table WHERE "some condition";

SELECT itemId, subData FROM otherTable WHERE itemId IN (id1, id2, ...);

Then just link up the sub-data to the primary data in a loop and
finally generate your JSON.

Does that clarify?
[/snip]

I must confess that the raging sinus headache and my general confusion
makes this really unclear for me today. Maybe I should just set it aside
for a day or so. I am super dense today.

Rest might do you well on a number of levels :)

For each level I am selecting for each parent in the level above. Let's
say that level 2 contains 8 people. Level 3 contains 14 people. Only
some of the 14 belong to the 8 and must be associated properly. So how
can I, with one query, associate level 3' 8th, 9th and 10th people with
level 2's 6th person keeping in mind that the 9th person might also
belong to level 2's 4th person.

At one point you indicated all the data was coming from one table. Can you send me the table fields and indicate which fields are used to determine parent child relationship? Also 2 sample rows of data which have a relationship would be helpful.

Just link up the sub-data? Place this array into a child array of the
parent array? Again I apologize - maybe I should push away and let the
customer know that it'll be a couple of more days.

Yeah... child array... 'children' :)

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
I've now fixed the iPad bugs in the menu component, and checked them on an
iPad in a nearby apple store.
Maybe it even works with iPhone now, if someone could check that for me I'd
be much obliged..

If you're interested, http://mediabeez.ws and the download zip there are
now updated with these latest improvements.

Have a nice day.

--- End Message ---
--- Begin Message ---
On Thu, Mar 22, 2012 at 1:01 PM, rene7705 <rene7...@gmail.com> wrote:

> I've now fixed the iPad bugs in the menu component, and checked them on an
> iPad in a nearby apple store.
> Maybe it even works with iPhone now, if someone could check that for me
> I'd be much obliged..
>
> Oh, never mind to check on iPhone, that page is 2.5mb in size or so, and
I'll just go to that apple store again to test it myself. Should've thought
of that when I was there this morning ;)


> If you're interested, http://mediabeez.ws and the download zip there are
> now updated with these latest improvements.
>
> Have a nice day.
>
>

--- End Message ---

Reply via email to