php-general Digest 7 Apr 2008 03:30:34 -0000 Issue 5390
Topics (messages 272589 through 272607):
Re: objects stored in sessions
272589 by: Richard Heyes
272591 by: Mark Weaver
272605 by: Kevin Waterson
Re: Posting Summary for Week Ending 4 April, 2008: [EMAIL PROTECTED]
272590 by: Zoltán Németh
272592 by: Daniel Brown
272593 by: Zoltán Németh
Include fails when "./" is in front of file name
272594 by: Noah Spitzer-Williams
272595 by: Casey
272603 by: Noah Spitzer-Williams
Arbitrary mathematical relations, not just hashes
272596 by: Kelly Jones
272598 by: Casey
272599 by: Mark J. Reed
272600 by: Greg Bowser
272601 by: Greg Bowser
272606 by: Mr. Shawn H. Corey
Re: Dynamic dropdown lists (select)
272597 by: Kevin Waterson
272602 by: Manuel Lemos
opening a big file
272604 by: Richard Lee
272607 by: Mr. Shawn H. Corey
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 ---
So, if I create a user object, set the properties of said user object
and store that object in the user session will that object be available
throughout the application from the session?
Yes. Just remember to include the class definition before you start the
session on subsequent pages, otherwise you will encounter problems. Or
alternatively use __autoload() to allow the class code to be loaded when
you start the session.
--
Richard Heyes
Employ me:
http://www.phpguru.org/cv
--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
So, if I create a user object, set the properties of said user object
and store that object in the user session will that object be
available throughout the application from the session?
Yes. Just remember to include the class definition before you start the
session on subsequent pages, otherwise you will encounter problems. Or
alternatively use __autoload() to allow the class code to be loaded when
you start the session.
sweet! thank you Richard.
--
Mark
-------------------------
the rule of law is good, however the rule of tyrants just plain sucks!
Real Tax Reform begins with getting rid of the IRS.
==============================================
Powered by CentOS5 (RHEL5)
--- End Message ---
--- Begin Message ---
On Sun, 2008-04-06 at 11:02 -0400, Mark Weaver wrote:
> So, if I create a user object, set the properties of said user object
> and store that object in the user session will that object be available
> throughout the application from the session?
http://phpro.org/tutorials/Introduction-To-PHP-Sessions.html#8
--- End Message ---
--- Begin Message ---
Daniel Brown írta:
On Sun, Apr 6, 2008 at 7:31 AM, Zoltán Németh <[EMAIL PROTECTED]> wrote:
PostTrack [Dan Brown] írta:
> 10 (3.4%) 33529 (8.5%) Zoltán Németh <znemeth at
alterationx dot hu>
> 1 (0.3%) 2502 (0.6%) Zoltán Németh <znemeth at
alterationx dot hu>
what's the difference? they should be added up, no?
Yes. Next week's report (and from there-on) should resolve that
once and for all.
By the way, I don't remember seeing you report that issue before.
Just the character problems.
maybe the problem didn't appear before, or I just didn't notice it...
greets,
Zoltán Németh
--- End Message ---
--- Begin Message ---
On Sun, Apr 6, 2008 at 11:27 AM, Zoltán Németh <[EMAIL PROTECTED]> wrote:
>
> maybe the problem didn't appear before, or I just didn't notice it...
It was the first time I'd noticed it myself, so it's possible that
it's the first time it happened. I really only noticed it because I
was specifically looking for your post count, since you hit the "top
5" the week prior, as you pointed out. ;-P When I was scanning the
list of the rest, your name popped out again --- easily, as well,
because Gmail doesn't appropriately handle non-US characters in the
message each week. At least not my account.
--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
--- End Message ---
--- Begin Message ---
Daniel Brown írta:
On Sun, Apr 6, 2008 at 11:27 AM, Zoltán Németh <[EMAIL PROTECTED]> wrote:
maybe the problem didn't appear before, or I just didn't notice it...
It was the first time I'd noticed it myself, so it's possible that
it's the first time it happened. I really only noticed it because I
was specifically looking for your post count, since you hit the "top
5" the week prior, as you pointed out. ;-P When I was scanning the
list of the rest, your name popped out again --- easily, as well,
because Gmail doesn't appropriately handle non-US characters in the
message each week. At least not my account.
anyway, thanks for fixing it :)
greets,
Zoltán Németh
--- End Message ---
--- Begin Message ---
This works:
include("file.inc.php");
This doesn't:
include("./file.inc.php");
I can't figure it out! PHPMyAdmin uses "./" so it's obviously not working.
Here's my environment:
Win2003 Server w/ IIS 6
PHP 5.2.5 setup as ISAPI
All PHP and httpdoc directories have read, write, and execute
permissions given to IIS_WPG, IIS_USER, and NETWORK SERVICE
PHP.ini's include path is: include_path = ".;.\includes;.\pear" (I've
also tried include_path = ".;./includes;./pear")
phpinfo() works fine.
Anyone have any ideas?
Thanks!
Noah
--- End Message ---
--- Begin Message ---
On Sun, Apr 6, 2008 at 2:17 PM, Noah Spitzer-Williams <[EMAIL PROTECTED]> wrote:
> This works:
> include("file.inc.php");
>
> This doesn't:
> include("./file.inc.php");
>
> I can't figure it out! PHPMyAdmin uses "./" so it's obviously not working.
>
> Here's my environment:
> Win2003 Server w/ IIS 6
> PHP 5.2.5 setup as ISAPI
> All PHP and httpdoc directories have read, write, and execute
> permissions given to IIS_WPG, IIS_USER, and NETWORK SERVICE
> PHP.ini's include path is: include_path = ".;.\includes;.\pear" (I've
> also tried include_path = ".;./includes;./pear")
> phpinfo() works fine.
>
> Anyone have any ideas?
>
> Thanks!
>
> Noah
>
>
Is that include() statement being issued within an included PHP page?
a.php
<?php
include('directory/b.php');
?>
directory/b.php
<?php
include('./c.php'); // Does this refer to c.php or directory/c.php
?>
--
-Casey
--- End Message ---
--- Begin Message ---
Casey -- nope. the include statement is being issues from the parent page.
both files are in the same directory.
Nitsan -- the problem is apps like phpMyAdmin are littered with
include("./file.inc.php"); i'd have to replace all those to use full
paths. it's not a good idea from a servicability statement anyways.
thanks!
On Sun, Apr 6, 2008 at 4:21 PM, Casey <[EMAIL PROTECTED]> wrote:
> On Sun, Apr 6, 2008 at 2:17 PM, Noah Spitzer-Williams <[EMAIL PROTECTED]>
> wrote:
> > This works:
> > include("file.inc.php");
> >
> > This doesn't:
> > include("./file.inc.php");
> >
> > I can't figure it out! PHPMyAdmin uses "./" so it's obviously not
> working.
> >
> > Here's my environment:
> > Win2003 Server w/ IIS 6
> > PHP 5.2.5 setup as ISAPI
> > All PHP and httpdoc directories have read, write, and execute
> > permissions given to IIS_WPG, IIS_USER, and NETWORK SERVICE
> > PHP.ini's include path is: include_path = ".;.\includes;.\pear"
> (I've
> > also tried include_path = ".;./includes;./pear")
> > phpinfo() works fine.
> >
> > Anyone have any ideas?
> >
> > Thanks!
> >
> > Noah
> >
> >
>
> Is that include() statement being issued within an included PHP page?
>
> a.php
> <?php
> include('directory/b.php');
> ?>
>
> directory/b.php
> <?php
> include('./c.php'); // Does this refer to c.php or directory/c.php
> ?>
>
> --
> -Casey
>
--- End Message ---
--- Begin Message ---
Many programming languages (including Perl, Ruby, and PHP) support hashes:
$color['apple'] = 'red';
$color['ruby'] = 'red';
$type['apple'] = 'fruit';
$type['ruby'] = 'gem';
This quickly lets me find the color or type of a given item.
In this sense, color() and type() are like mathematical functions.
However, I can't easily find all items whose $color is 'red', nor all
items whose $type is 'fruit'. In other words, color() and type()
aren't full mathematical relations.
Of course, I could create the inverse function as I go along:
$inverse_color['red'] = ['apple', 'ruby']; # uglyish, assigning list to value
and there are many other ways to do this, but they all seem kludgey.
Is there a clean way to add 'relation' support to Perl, Ruby, or PHP?
Is there a language that handles mathematical relations naturally/natively?
I realize SQL does all this and more, but that seems like overkill for
something this simple?
--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.
--- End Message ---
--- Begin Message ---
On Sun, Apr 6, 2008 at 4:52 PM, Kelly Jones <[EMAIL PROTECTED]> wrote:
> Many programming languages (including Perl, Ruby, and PHP) support hashes:
>
> $color['apple'] = 'red';
> $color['ruby'] = 'red';
>
> $type['apple'] = 'fruit';
> $type['ruby'] = 'gem';
>
> This quickly lets me find the color or type of a given item.
>
> In this sense, color() and type() are like mathematical functions.
>
> However, I can't easily find all items whose $color is 'red', nor all
> items whose $type is 'fruit'. In other words, color() and type()
> aren't full mathematical relations.
>
> Of course, I could create the inverse function as I go along:
>
> $inverse_color['red'] = ['apple', 'ruby']; # uglyish, assigning list to value
>
> and there are many other ways to do this, but they all seem kludgey.
>
> Is there a clean way to add 'relation' support to Perl, Ruby, or PHP?
>
> Is there a language that handles mathematical relations naturally/natively?
>
> I realize SQL does all this and more, but that seems like overkill for
> something this simple?
>
> --
> We're just a Bunch Of Regular Guys, a collective group that's trying
> to understand and assimilate technology. We feel that resistance to
> new ideas and technology is unwise and ultimately futile.
>
Something like this?
<?php
$objects = array(
'apple' => array(
'type' => 'fruit',
'color' => 'red'
),
'ruby' => array(
'type' => 'gem',
'color' => 'red'
)
);
// Search for all red objects.
$red = array();
foreach ($objects as $name => $object) {
if ($object['type'] == 'red')
$red[] = $name;
}
?>
--
-Casey
--- End Message ---
--- Begin Message ---
As far as languages with two-way relation go, there are many; perhaps
the most prototypical is Lisp, in that either member of a pair within
an alist can be used to look the pair up, with no extra function or
second map definition required.
But PHP has pretty good support, too, actually. If you have a 1-to-1
relation, you can use array_flip() to get a second array with the keys
and values swapped in one go. If you have a 1-to-many, as in this
case, you can use the optional search parameter to array_keys:
>>> $color = array('apple' => 'red', 'ruby' => 'red', 'banana' => 'yellow');
>>> array_keys($color, 'red')
Array
(
[0] => apple
[1] => ruby
)
--- End Message ---
--- Begin Message ---
On Sun, Apr 6, 2008 at 7:52 PM, Kelly Jones <[EMAIL PROTECTED]>
wrote:
> Many programming languages (including Perl, Ruby, and PHP) support hashes:
>
> $color['apple'] = 'red';
> $color['ruby'] = 'red';
>
> $type['apple'] = 'fruit';
> $type['ruby'] = 'gem';
>
> This quickly lets me find the color or type of a given item.
>
> In this sense, color() and type() are like mathematical functions.
>
> However, I can't easily find all items whose $color is 'red', nor all
> items whose $type is 'fruit'. In other words, color() and type()
> aren't full mathematical relations.
>
> Of course, I could create the inverse function as I go along:
>
> $inverse_color['red'] = ['apple', 'ruby']; # uglyish, assigning list to
> value
>
> and there are many other ways to do this, but they all seem kludgey.
>
> Is there a clean way to add 'relation' support to Perl, Ruby, or PHP?
>
> Is there a language that handles mathematical relations
> naturally/natively?
>
> I realize SQL does all this and more, but that seems like overkill for
> something this simple?
>
> --
> We're just a Bunch Of Regular Guys, a collective group that's trying
> to understand and assimilate technology. We feel that resistance to
> new ideas and technology is unwise and ultimately futile.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
(sorry I just hit send on a blank email; I'm absent-minded)
First, in the strictest mathematical sense, a relation from a set $a to a
set $b is a subset of the cross-product $a x $b.
(obviously, the mathematical notation is not a great way to represent this
in a program.)
Hence, a relation is a set of ordered pairs: array(array('apple','red'),
array('ruby','red')) is a relation from the objects to the colors.
For a relation R from A to B, the inverse relation is defined by (b,a) for
all a in A and B in b.
Thus, the inverse relation of objects ~ colors would be:
array(array('red','apple'), array('red','ruby')).
A function is a special case of a relation: functions have the property that
if a in A is related to b in B by the relation R and a is related to c by
the relation R, then a = c.
It follows that mathematically, there is no function f:color->object.
As you suggest, each element of the relation colors~objects relation must
return a list in order to be a function.
So... How does SQL solve this problem?
SQL has indexes. You have a list of objects:
<?
$objects = array(
array(
'name'=>'apple',
'type' => 'fruit',
'color' => 'red'
),
array(
'name' => 'ruby',
'type' => 'gem',
'color' => 'red'
)
);
?>
Given a type, you would like to find all objects with that type. One way to
accomplish this might be:
<?php
function locate($property,$value,$objects) {
$return = array();
foreach ($objects as $object) {
if ($object[$property] == $value)
$return[] = $objects;
}
return $return;
}
?>
Obviously, the time increased to complete a search will increase with the
size of the $objects array. This is where the indexes come in: Suppose we
would like to easily be able to locate an object given a color, a type, or
its name:
<?php
//array, indexed by $property. Each element is an array of numbers, n,
corresponding to $objects[n].
$indexes = array();
//properties to index
$keys = array('color','type','name');
//initialize
foreach ($keys as $key)
$indexes[$key] = array();
//this accomplishes the same thing as array_flip() ;)
foreach ($objects as $n => $object) foreach ($keys as $key) {
if (!isset($indexes[$key][$object[$key]]))
$indexes[$key][$object[$key]] = array();
$indexes[$key][$object[$key]][] = $n;
}
?>
The above produces the following array:
Array
(
[color] => Array
(
[red] => Array
(
[0] => 0
[1] => 1
)
)
[type] => Array
(
[fruit] => Array
(
[0] => 0
)
[gem] => Array
(
[0] => 1
)
)
[name] => Array
(
[apple] => Array
(
[0] => 0
)
[ruby] => Array
(
[0] => 1
)
)
)
Conceptually, this is all SQL does.
Anyway... I wouldn't actually do any of that in an application. I'd probably
go with what Casey suggested.
-- GREG
Disclaimer: The above is intended only to be conceptual. Any attempt at
parsing may fail. Technical accuracy is not guaranteed.
P.S. Sorry for the math. I was bored :p
> However, I can't easily find all items whose $color is 'red', nor all
> items whose $type is 'fruit'. In other words, color() and type()
> aren't full mathematical relations.
>
> Of course, I could create the inverse function as I go along:
>
> $inverse_color['red'] = ['apple', 'ruby']; # uglyish, assigning list to
value
By definition, not all relations are functions, nor all functions
invertible.
The function inverse_color(object) specifies more than
What you're referring to sounds like an index: given an object, you can easi
On Sun, Apr 6, 2008 at 8:15 PM, Casey <[EMAIL PROTECTED]> wrote:
> On Sun, Apr 6, 2008 at 4:52 PM, Kelly Jones <[EMAIL PROTECTED]>
> wrote:
> > Many programming languages (including Perl, Ruby, and PHP) support
> hashes:
> >
> > $color['apple'] = 'red';
> > $color['ruby'] = 'red';
> >
> > $type['apple'] = 'fruit';
> > $type['ruby'] = 'gem';
> >
> > This quickly lets me find the color or type of a given item.
> >
> > In this sense, color() and type() are like mathematical functions.
> >
> > However, I can't easily find all items whose $color is 'red', nor all
> > items whose $type is 'fruit'. In other words, color() and type()
> > aren't full mathematical relations.
> >
> > Of course, I could create the inverse function as I go along:
> >
> > $inverse_color['red'] = ['apple', 'ruby']; # uglyish, assigning list to
> value
> >
> > and there are many other ways to do this, but they all seem kludgey.
> >
> > Is there a clean way to add 'relation' support to Perl, Ruby, or PHP?
> >
> > Is there a language that handles mathematical relations
> naturally/natively?
> >
> > I realize SQL does all this and more, but that seems like overkill for
> > something this simple?
> >
> > --
> > We're just a Bunch Of Regular Guys, a collective group that's trying
> > to understand and assimilate technology. We feel that resistance to
> > new ideas and technology is unwise and ultimately futile.
> >
>
>
> Something like this?
>
> <?php
> $objects = array(
> 'apple' => array(
> 'type' => 'fruit',
> 'color' => 'red'
> ),
> 'ruby' => array(
> 'type' => 'gem',
> 'color' => 'red'
> )
> );
>
> // Search for all red objects.
> $red = array();
> foreach ($objects as $name => $object) {
> if ($object['type'] == 'red')
> $red[] = $name;
> }
>
> ?>
> --
> -Casey
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Sun, 2008-04-06 at 16:52 -0700, Kelly Jones wrote:
> Many programming languages (including Perl, Ruby, and PHP) support hashes:
>
> $color['apple'] = 'red';
> $color['ruby'] = 'red';
>
> $type['apple'] = 'fruit';
> $type['ruby'] = 'gem';
>
> This quickly lets me find the color or type of a given item.
>
> In this sense, color() and type() are like mathematical functions.
>
> However, I can't easily find all items whose $color is 'red', nor all
> items whose $type is 'fruit'. In other words, color() and type()
> aren't full mathematical relations.
>
> Of course, I could create the inverse function as I go along:
>
> $inverse_color['red'] = ['apple', 'ruby']; # uglyish, assigning list to value
>
> and there are many other ways to do this, but they all seem kludgey.
>
> Is there a clean way to add 'relation' support to Perl, Ruby, or PHP?
Yes, create a class/object to handle the relationship. That way, the
details are hidden and may be anything you want.
E.g.
use Relationship;
my $color = new Relatinship;
$color->add( 'apple', 'red' );
$color->add( 'ruby', 'red' );
my $type = new Relationship;
$type->add( 'apple', 'fruit' );
$type->add( 'ruby', 'gem' );
my @red_things = $color->find( undef, 'red' );
--
Just my 0.00000002 million dollars worth,
Shawn
99% of you are just big dumb apes!
+------------\
| Shangri La \
| 40,000 KM /
+------------/
--- End Message ---
--- Begin Message ---
On Fri, 2008-04-04 at 12:51 +0200, Angelo Zanetti wrote:
> So there will be 2 dropdown lists. First one say gets (for example) a list
> of cars,
>
> Then once the car is choosen the second list is populated with the list of
> models for the car choosen.
Try something like this->
http://phpro.org/tutorials/Creating-Dropdowns-with-PHP-and-Xajax.html
It gives you goodness you desire
Kevin
--- End Message ---
--- Begin Message ---
Hello,
on 04/04/2008 07:51 AM Angelo Zanetti said the following:
> I am looking at options for creating a dynamic dropdown list.
>
> Ok here is the scenario:
>
> All values in the dropdown list (select/option field) are coming from the
> database.
>
> So there will be 2 dropdown lists. First one say gets (for example) a list
> of cars,
>
> Then once the car is choosen the second list is populated with the list of
> models for the car choosen.
>
> I would like to know if its possible to do this without posting as well as
> without the use of JS. I have seen js examples where the values are all
> stored in arrays.
>
> This is not desireable as I will be getting the values from the the DB using
> PHP, unless I can write the JS values to the arrays using PHP? Also not sure
> of that.
>
> Is there any other idea or thing I can do? Im thinking maybe AJAX but this
> is for a mobile site (WAP/xHTML) site and Im not sure if the functionality
> will work on these devices.
This forms generation class comes with a plug-in that does exactly that.
http://www.phpclasses.org/formsgeneration
It requires some Javascript to send AJAX request to the server, so the
plug-in itself queries the database and sends the select input options o
the browser. But you do not have to worry because the class generates
all the necessary Javascript for you.
Here is a live example of the plug-in:
http://www.meta-language.net/forms-examples.html?example=test_linked_select
You may also want to watch this tutorial video:
http://www.phpclasses.org/browse/video/1/package/1/section/plugin-linked-select.html
--
Regards,
Manuel Lemos
PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/
PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
--- End Message ---
--- Begin Message ---
I am trying to open a big file and go through line by line while
limiting the resource on the system.
What is the best way to do it?
Does below read the entire file and store them in memory(not good if
that's the case)..
open(SOURCE, "/tmp/file") || die "not there: $!\n";
while (<SOURCE>) {
## do something
}
sometime ago I saw somewhere it had something like below which look like
it was reading them and going through line by line without storing them
all in memory.
I just cannot remember the syntax exactly.
open(SOURCE, " /tmp/file |") || die "not there: $!\n";
while (<>) {
## do something
}
--- End Message ---
--- Begin Message ---
On Sun, 2008-04-06 at 22:36 -0400, Richard Lee wrote:
> I am trying to open a big file and go through line by line while
> limiting the resource on the system.
> What is the best way to do it?
>
> Does below read the entire file and store them in memory(not good if
> that's the case)..
>
> open(SOURCE, "/tmp/file") || die "not there: $!\n";
> while (<SOURCE>) {
> ## do something
> }
The above code will read the file one line at a time. It is recommended
that you use the three-argument open statement. (See `perldoc -f
open`).
open( SOURCE, '<', "/tmp/file" ) || die "cannot open /tmp/file: $!\n";
while (<SOURCE>) {
# do something
}
>
> sometime ago I saw somewhere it had something like below which look like
> it was reading them and going through line by line without storing them
> all in memory.
> I just cannot remember the syntax exactly.
>
> open(SOURCE, " /tmp/file |") || die "not there: $!\n";
> while (<>) {
> ## do something
>
> }
This syntax is is used for reading the output of another command. It is
not recommended because your program would not be portable across
operating systems. But sometimes you have no choice.
open( SOURCE, '-|', "command" ) || die "cannot pipe from command: $!\n";
while (<SOURCE>) {
# do something
}
Also see `perldoc IPC::Open2` and `perldoc IPC::Open3`
--
Just my 0.00000002 million dollars worth,
Shawn
99% of you are just big dumb apes!
+------------\
| Shangri La \
| 40,000 KM /
+------------/
--- End Message ---