[PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Anton Heuschen
This might sound trivial, but for the live of me cant seem to get it to
work, and I am not familiar with such a thing.

What I have is a query lets say :

select  country,name,population from USERS where id= 'some_id' ";


Now I want to assign the result to one set (The above example might have 3+
entries per telephone, thus what would be nice is something like an array of
:


[id][country][name]  = population .. or to be exact if I echo the
value for each id and country and name to get the population value


Like :

Array {

  [id] array {
 [country] array {
[0] = USA
  }
  [name] array {
 [0] = test

  }

}




I dont know something like that, maybe Im over comlicating the question now
even, the main thing is wondered was in the first place was with a standard
query and variable assign, from the query like:

select  country,name,population from USERS where id= 'some_id' ";

normally you would just assign each field to one variable. like

$country = result["country"]
$name = result["name"]


But now I want all 3 fields as one variable (which would be an array) ..but
how ?

I hope I have not totally confused the question now.

Thanks in advance


[PHP] User Authentication across multiple server

2009-03-06 Thread Edmund Hertle
Hey,

I've got 2 server, both having the same authentication scripts and using the
same database. My problems are:
1.: User logs in on server1 -> trys to use a part of the site which is
physically located on server2 -> has to login again on server2
2.: There is a wiki on server2, which also depends on the same
user-database-table. Is there a way to login the user automatically to that
wiki?

The only method which possibly could work and came to my mind was using
somehow $_GET parameter for username and password (encrypted).

Thoughts?

-eddy


Re: [PHP] User Authentication across multiple server

2009-03-06 Thread Paul Scott
On Fri, 2009-03-06 at 10:09 +0100, Edmund Hertle wrote:

> The only method which possibly could work and came to my mind was using
> somehow $_GET parameter for username and password (encrypted).

Set a cookie and crypt that (RC4 works well) and then check for the
cookie on both sites. Kind of like a "Remember me" type deal

-- Paul


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] User Authentication across multiple server

2009-03-06 Thread j's php general
On Fri, Mar 6, 2009 at 5:14 PM, Paul Scott  wrote:
> On Fri, 2009-03-06 at 10:09 +0100, Edmund Hertle wrote:
>
>> The only method which possibly could work and came to my mind was using
>> somehow $_GET parameter for username and password (encrypted).
>
> Set a cookie and crypt that (RC4 works well) and then check for the
> cookie on both sites. Kind of like a "Remember me" type deal
>
> -- Paul
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I believe you can do this with a database to handle session, I haven't
used that myself though.

-- 
-
http://www.lampadmins.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Website on a USB key?

2009-03-06 Thread Robert Cummings
On Fri, 2009-03-06 at 01:40 -0500, Paul M Foster wrote:
> On Fri, Mar 06, 2009 at 04:24:24PM +1100, Clancy wrote:
> 
> > I bought some appliance recently, and found that they had thrown in a 2G
> > USB key for good
> > luck.  I guess I ought to be able to put a PHP server plus a copy of my
> > website on it for
> > demonstration purposes, but has anyone actually tried it, and if so are
> > there any traps to
> > avoid?
> 
> Maybe I'm dense or I don't understand your question. It sounds like you
> want to run lighttpd or apache on this USB device in order to serve up
> your website. If so, then the device would have to be assigned a
> separate IP address from the machine it's mounted on. Someone would have
> to be able to surf to that IP at least, much less have the IP address
> translated into a name. Otherwise, there's no way a web server can serve
> up a website; it has to have an IP address. I don't know how you'd
> possibly do that. Even then, you'd have to mount the device and then
> issue a separate call to the USB-hosted web server to start, and then
> serve your site up.

127.0.0.1 and name localhost should suffice. You might want to use a
non-standard port so that it doesn't conflict with anything else the
machine is running.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] User Authentication across multiple server

2009-03-06 Thread Michael A. Peters

Edmund Hertle wrote:

Hey,

I've got 2 server, both having the same authentication scripts and using the
same database. My problems are:
1.: User logs in on server1 -> trys to use a part of the site which is
physically located on server2 -> has to login again on server2
2.: There is a wiki on server2, which also depends on the same
user-database-table. Is there a way to login the user automatically to that
wiki?

The only method which possibly could work and came to my mind was using
somehow $_GET parameter for username and password (encrypted).

Thoughts?

-eddy



Do you use the database for your session management?
If you do, since both servers talk to the same database, it should be easy.

ini_set("session.cookie_domain",".yourdomain.org");

Any server on your domain will be able to read the session cookie, and 
if your sessions are database driven, authenticate the session ID.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Dollah Ihsan
I'm sorry if this is not what you're talking about...

/**
 * assume your table structure just like this.
 * table: users
 * |  id  |   country| name   |  population |
 * --
 * |  1   |Texas |  Fort Worth  |40|
 *
 */

function getPopulationById($id) {
// echo 'SELECT country, name, population FROM users WHERE id = ' . 
$id;die;
$result = mysql_query('SELECT country, name, population FROM users
WHERE id = ' . $id);
if(mysql_num_rows($result) != 1) return false;
$row = mysql_fetch_assoc($result);
$pop[$id][$row['country']][$row['name']] = $row['population'];
return $pop;
}

$array = getPopulationById(1);
print_r($array);
// print_r($array) should be like this:
// Array ( [1] => Array ( [Texas] => Array ( [Fort Worth] => 40 ) ) )

On Fri, Mar 6, 2009 at 3:41 PM, Anton Heuschen  wrote:
>
> This might sound trivial, but for the live of me cant seem to get it to
> work, and I am not familiar with such a thing.
>
> What I have is a query lets say :
>
> select  country,name,population from USERS where id= 'some_id' ";
>
>
> Now I want to assign the result to one set (The above example might have 3+
> entries per telephone, thus what would be nice is something like an array of
> :
>
>
> [id][country][name]  = population .. or to be exact if I echo the
> value for each id and country and name to get the population value
>
>
> Like :
>
> Array {
>
>  [id] array {
>         [country] array {
>                    [0] = USA
>          }
>  [name] array {
>         [0] = test
>
>  }
>
> }
>
>
>
>
> I dont know something like that, maybe Im over comlicating the question now
> even, the main thing is wondered was in the first place was with a standard
> query and variable assign, from the query like:
>
> select  country,name,population from USERS where id= 'some_id' ";
>
> normally you would just assign each field to one variable. like
>
> $country = result["country"]
> $name = result["name"]
>
>
> But now I want all 3 fields as one variable (which would be an array) ..but
> how ?
>
> I hope I have not totally confused the question now.
>
> Thanks in advance

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Sending out large amounts of email

2009-03-06 Thread Richard Heyes
Hi,

> Our company is merging with another company and newsletter now needs to go
> out to more than 100.000 people.

Out source it. It will cost you far less in the long run. And the
short run. I tried Jango mail and they seemed OK, though I didn't have
to talk to their support, and my use was very brief. These types of
company will also have far more success in getting the emails
delivered (and not flagged as spam).

-- 
Richard Heyes

HTML5 Canvas graphing for Firefox, Chrome, Opera and Safari:
http://www.rgraph.net (Updated February 28th)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP script lag (5 secs) when declaring mime type.

2009-03-06 Thread Jsbeginner

Thankyou for the help,

I will contact the script maintainer to ask him to work on this problem 
for future updates, and for the moment I've commented out the line that 
specifies the length.
I suppose that it won't cause any problems with files that are sent 
through this script that are not gzipped (this script allows html, js, 
css (all compressed with gzip) as well as images that aren't compressed.


From what I understand the best would be to detect if gzip is activated 
for each file and only allow the header to specify the length if the 
file is not planned to be compressed with gzip (images etc).


Thanks again :)

Nisse Engström a écrit :

On Thu, 5 Mar 2009 19:14:20 +0100, Nisse Engström wrote:

  

On Thu, 05 Mar 2009 15:45:35 +0100, Jsbeginner wrote:





test.js is only a few lines long, and if I remove the header content 
type the file loads instantaniously do it's not a problem with readfile.
I thought about zlib gzip taking maybe a long time to load but I've 
changed the compression level from 6 to 1 and the file still has a the 
same lag.
  

Content-Length MUST NOT be sent when using a
Transfer-Encoding (eg. gzip).

See: 



And I goofed: Transfer-Encoding is the stuff that says
"chunked". I was thinking of Content-Encoding. But the
section I refered to also says:

  "If a Content-Length header field (section 14.13) is present, its
   decimal value in OCTETs represents both the entity-length and the
   transfer-length. The Content-Length header field MUST NOT be sent
   if these two lengths are different"

[And a little further down, it mentions "that the
 recipient can arse it". I'm not sure quite what
 to make of that. :-)]

 -   -   -

Come to think about it, I've written some output handlers
to convert utf-8 to utf-16 or -32, which uses either
'Content-Length' or 'Transfer-Encoding: chunked' depending
on the size of the output. Perhaps I should change that to
always 'chunked'...


/Nisse

  




Re: [PHP] Conclusion of "use strict"...

2009-03-06 Thread Hans Schultz
Hehe,I don't agree with either :-) But I am still searching for some solution, 
and when (and if) I find it I will be happy to share with you (btw, obviously 
nobody shared experiences about that compiler)



Hans is the OP, the one you thought "got it all wrong.", you're actually

agree with me ... which is as natural as it is inevitable ;-)



LOL, right  :)




  

RE: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Chetan Rane
Hi this is similar to what Dollah Ihsan had suggested , however I ave
tweeked the getPopulationById function a bit.
/**
 * assume your table structure just like this.
 * table: users
 * |  id  |   country| name   |  population |
 * --
 * |  1   |Texas |  Fort Worth  |40|
 *
 */

function getPopulationById($id) {
// echo 'SELECT country, name, population FROM users WHERE id = ' .
$id;die;
$result = mysql_query('SELECT country, name, population FROM users
WHERE id = ' . $id);
While($row = mysql_fetch_assoc($result)) 
$pop[$id][$row['country']][$row['name']] =
$row['population'];
return $pop;
}


Chetan Dattaram Rane | Software Engineer | Persistent Systems
chetan_r...@persistent.co.in  | Cell: +91 94033 66714 | Tel: +91 (0832) 30
79014
Innovation in software product design, development and delivery-
www.persistentsys.com




-Original Message-
From: Dollah Ihsan [mailto:dollah.ih...@gmail.com] 
Sent: Friday, March 06, 2009 3:04 PM
To: Anton Heuschen
Cc: php-general@lists.php.net
Subject: Re: [PHP] Assign 2 values from Mysql to an array

I'm sorry if this is not what you're talking about...

/**
 * assume your table structure just like this.
 * table: users
 * |  id  |   country| name   |  population |
 * --
 * |  1   |Texas |  Fort Worth  |40|
 *
 */

function getPopulationById($id) {
// echo 'SELECT country, name, population FROM users WHERE id = ' .
$id;die;
$result = mysql_query('SELECT country, name, population FROM users
WHERE id = ' . $id);
if(mysql_num_rows($result) != 1) return false;
$row = mysql_fetch_assoc($result);
$pop[$id][$row['country']][$row['name']] = $row['population'];
return $pop;
}

$array = getPopulationById(1);
print_r($array);
// print_r($array) should be like this:
// Array ( [1] => Array ( [Texas] => Array ( [Fort Worth] => 40 ) ) )

On Fri, Mar 6, 2009 at 3:41 PM, Anton Heuschen  wrote:
>
> This might sound trivial, but for the live of me cant seem to get it to
> work, and I am not familiar with such a thing.
>
> What I have is a query lets say :
>
> select  country,name,population from USERS where id= 'some_id' ";
>
>
> Now I want to assign the result to one set (The above example might have
3+
> entries per telephone, thus what would be nice is something like an array
of
> :
>
>
> [id][country][name]  = population .. or to be exact if I echo the
> value for each id and country and name to get the population value
>
>
> Like :
>
> Array {
>
>  [id] array {
>         [country] array {
>                    [0] = USA
>          }
>  [name] array {
>         [0] = test
>
>  }
>
> }
>
>
>
>
> I dont know something like that, maybe Im over comlicating the question
now
> even, the main thing is wondered was in the first place was with a
standard
> query and variable assign, from the query like:
>
> select  country,name,population from USERS where id= 'some_id' ";
>
> normally you would just assign each field to one variable. like
>
> $country = result["country"]
> $name = result["name"]
>
>
> But now I want all 3 fields as one variable (which would be an array)
..but
> how ?
>
> I hope I have not totally confused the question now.
>
> Thanks in advance

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Sending out large amounts of email

2009-03-06 Thread Bob McConnell
From: Chris
> Brian Hansen wrote:
>> 2009/3/6 Chris mailto:dmag...@gmail.com>>
>>  
>> 
>> What about 10,000?
>> 
>> 
>> I haven't been able to send out more than 6000 at most. It is
proberly 
>> caused by a limit set in Postfix as you wrote.
> 
> If you're sending emails one by one in a mail() call there is no limit

> (one email per recipient)
> 
> If you're trying to cc or bcc the email addresses, then there probably

> is a limit.

You should also talk to your ISP and email admins to find out how to
avoid ending up on a SPAM blacklist after sending out that many emails.
You're likely to trigger more than one automatic listing with that many
messages.

Bob McConnell

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Missing ANNOUNCE email: PHP 5.2.9

2009-03-06 Thread Steven Chamberlain
Hi,

I learned only today that PHP 5.2.9 had been released on 2009-02-26 and
fixed security vulnerabilities.

I've checked, and there was no ANNOUNCE email for this version, as can
be verified here:

  http://news.php.net/group.php?group=php.announce

I've come to rely on these useful email notifications to tell me when a
new version is out, as I don't often check the site.

Maybe someone forgot this time?  Or something went wrong and it didn't
get distributed?

Thanks,
-- 
Steven Chamberlain
ste...@pyro.eu.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP script lag (5 secs) when declaring mime type.

2009-03-06 Thread 9el
On Fri, Mar 6, 2009 at 4:18 PM, Jsbeginner wrote:

> Thankyou for the help,
>
> I will contact the script maintainer to ask him to work on this problem for
> future updates, and for the moment I've commented out the line that
> specifies the length.
> I suppose that it won't cause any problems with files that are sent through
> this script that are not gzipped (this script allows html, js, css (all
> compressed with gzip) as well as images that aren't compressed.
>
> From what I understand the best would be to detect if gzip is activated for
> each file and only allow the header to specify the length if the file is not
> planned to be compressed with gzip (images etc).


As we discussed, the declaration of size of the file is COMPLETELY
unnecessary in this case.
Lenin  www.twitter.com/nine_L

>
>
> Thanks again :)
>
> Nisse Engström a écrit :
>
>  On Thu, 5 Mar 2009 19:14:20 +0100, Nisse Engström wrote:
>>
>>
>>
>>> On Thu, 05 Mar 2009 15:45:35 +0100, Jsbeginner wrote:
>>>
>>>
>>>
 >>> header('Content-Type: application/x-javascript');
 header('Content-Length: '.filesize('test.js'));
 readfile('test.js');
 ?>

 test.js is only a few lines long, and if I remove the header content
 type the file loads instantaniously do it's not a problem with readfile.
 I thought about zlib gzip taking maybe a long time to load but I've
 changed the compression level from 6 to 1 and the file still has a the same
 lag.


>>> Content-Length MUST NOT be sent when using a
>>> Transfer-Encoding (eg. gzip).
>>>
>>> See: 
>>>
>>>
>>
>> And I goofed: Transfer-Encoding is the stuff that says
>> "chunked". I was thinking of Content-Encoding. But the
>> section I refered to also says:
>>
>>  "If a Content-Length header field (section 14.13) is present, its
>>   decimal value in OCTETs represents both the entity-length and the
>>   transfer-length. The Content-Length header field MUST NOT be sent
>>   if these two lengths are different"
>>
>> [And a little further down, it mentions "that the
>>  recipient can arse it". I'm not sure quite what
>>  to make of that. :-)]
>>
>>  -   -   -
>>
>> Come to think about it, I've written some output handlers
>> to convert utf-8 to utf-16 or -32, which uses either
>> 'Content-Length' or 'Transfer-Encoding: chunked' depending
>> on the size of the output. Perhaps I should change that to
>> always 'chunked'...
>>
>>
>> /Nisse
>>
>>
>>
>
>


Re: [PHP] Website on a USB key?

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 3:24 AM, Robert Cummings  wrote:
> On Fri, 2009-03-06 at 01:40 -0500, Paul M Foster wrote:
>> On Fri, Mar 06, 2009 at 04:24:24PM +1100, Clancy wrote:
>>
>> > I bought some appliance recently, and found that they had thrown in a 2G
>> > USB key for good
>> > luck.  I guess I ought to be able to put a PHP server plus a copy of my
>> > website on it for
>> > demonstration purposes, but has anyone actually tried it, and if so are
>> > there any traps to
>> > avoid?
>>
>> Maybe I'm dense or I don't understand your question. It sounds like you
>> want to run lighttpd or apache on this USB device in order to serve up
>> your website. If so, then the device would have to be assigned a
>> separate IP address from the machine it's mounted on. Someone would have
>> to be able to surf to that IP at least, much less have the IP address
>> translated into a name. Otherwise, there's no way a web server can serve
>> up a website; it has to have an IP address. I don't know how you'd
>> possibly do that. Even then, you'd have to mount the device and then
>> issue a separate call to the USB-hosted web server to start, and then
>> serve your site up.
>
> 127.0.0.1 and name localhost should suffice. You might want to use a
> non-standard port so that it doesn't conflict with anything else the
> machine is running.


I've been running XAMPP and even Eclipse from my USB key for well over
a year now. It works like a charm. Fantastic for demonstrations, or if
you've got a pet project that you need to test and carry with you.


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] include question

2009-03-06 Thread PJ
good morning all,

How can I include src and href in include files that will refer the
right paths from files in different hierarchies(directory tree levels)?
Example:
include dirname(_FILE_)."/../lib/header1.php"; ?

This does not work:
snippetysnip...


Nor does this: (NOTE THE DIFFERENCES " AND ' IN THE SRC AND HREF)

http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] include question

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 08:37, PJ  wrote:
> good morning all,
>
> How can I include src and href in include files that will refer the
> right paths from files in different hierarchies(directory tree levels)?
> Example:
> include dirname(_FILE_)."/../lib/header1.php"; ?
>
> This does not work:
> snippetysnip...
>  type="text/css">
> 
> Nor does this: (NOTE THE DIFFERENCES " AND ' IN THE SRC AND HREF)
> 
>     Perhaps it's not possible?

It is when it's parsed by PHP.  You're just putting it through as
straight HTML, which - even though it may have a .php extension -
won't work as you might be expecting.

Instead, you have to instruct the parsing engine where and when to
interpret, compile, and execute the code, like so:



In the above snippet, notice a few very important things:

1.) We use regular open tags to be compatible with all stock
PHP configurations.
2.) We echo out the response from dirname() so that it's
output to the HTML source.
3.) We use dirname() twice, so it gives the dirname() of the
dirname(), rather than '..'.
4.) There are double underscores around FILE.  The same is
true with LINE, FUNCTION, etc.



-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Website on a USB key?

2009-03-06 Thread Sean O

Another good website-on-a-stick software is... well, WOS (now called MoWeS --
Modular Webserver System).
http://www.chsoftware.net/en/useware/mowes/mowes.htm

The nice thing about this software is the ability to download "packages" of
just about any major server-based software -- Drupal, Mambo, Joomla, Moodle,
SugarCRM, WordPress, etc.
http://www.chsoftware.net/en/useware/mowesmixer/mowesmixer.htm?step=2

And, of course, run it all from your USB Drive.


SEAN O
http://www.sean-o.com



haliphax wrote:
> 
> On Fri, Mar 6, 2009 at 3:24 AM, Robert Cummings 
> wrote:
>> On Fri, 2009-03-06 at 01:40 -0500, Paul M Foster wrote:
>>> On Fri, Mar 06, 2009 at 04:24:24PM +1100, Clancy wrote:
>>>
>>> > I bought some appliance recently, and found that they had thrown in a
>>> 2G
>>> > USB key for good
>>> > luck.  I guess I ought to be able to put a PHP server plus a copy of
>>> my
>>> > website on it for
>>> > demonstration purposes, but has anyone actually tried it, and if so
>>> are
>>> > there any traps to
>>> > avoid?
>>>
>>> Maybe I'm dense or I don't understand your question. It sounds like you
>>> want to run lighttpd or apache on this USB device in order to serve up
>>> your website. If so, then the device would have to be assigned a
>>> separate IP address from the machine it's mounted on. Someone would have
>>> to be able to surf to that IP at least, much less have the IP address
>>> translated into a name. Otherwise, there's no way a web server can serve
>>> up a website; it has to have an IP address. I don't know how you'd
>>> possibly do that. Even then, you'd have to mount the device and then
>>> issue a separate call to the USB-hosted web server to start, and then
>>> serve your site up.
>>
>> 127.0.0.1 and name localhost should suffice. You might want to use a
>> non-standard port so that it doesn't conflict with anything else the
>> machine is running.
> 
> 
> I've been running XAMPP and even Eclipse from my USB key for well over
> a year now. It works like a charm. Fantastic for demonstrations, or if
> you've got a pet project that you need to test and carry with you.
> 
> 
> -- 
> // Todd
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Website-on-a-USB-key--tp22366414p22372871.html
Sent from the PHP - General mailing list archive at Nabble.com.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 00:12, Clancy  wrote:
>
> Don't take me too seriously on this. But it riles me that the same peoplewho 
> threw out the
> GOTO as being too dangerous could then introduce the break statement which, 
> as I said,
> it's like a GOTO without a target. As a long-time assembly programmer, I 
> found the
> judicious use of GOTO's made for far clearer code than the mess of nested 
> braces I am
> forced to use in PHP.

Then you'll be happy with the advent of PHP6:

http://php.net/goto

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] include question

2009-03-06 Thread Stuart
2009/3/6 Daniel Brown 

> On Fri, Mar 6, 2009 at 08:37, PJ  wrote:
> > good morning all,
> >
> > How can I include src and href in include files that will refer the
> > right paths from files in different hierarchies(directory tree levels)?
> > Example:
> > include dirname(_FILE_)."/../lib/header1.php"; ?
> >
> > This does not work:
> > snippetysnip...
> >  > type="text/css">
> > 
> > Nor does this: (NOTE THE DIFFERENCES " AND ' IN THE SRC AND HREF)
> > 
> > > Perhaps it's not possible?
>
> It is when it's parsed by PHP.  You're just putting it through as
> straight HTML, which - even though it may have a .php extension -
> won't work as you might be expecting.
>
>Instead, you have to instruct the parsing engine where and when to
> interpret, compile, and execute the code, like so:
>
> 
>
>In the above snippet, notice a few very important things:
>
>1.) We use regular open tags to be compatible with all stock
> PHP configurations.
>2.) We echo out the response from dirname() so that it's
> output to the HTML source.
>3.) We use dirname() twice, so it gives the dirname() of the
> dirname(), rather than '..'.
>4.) There are double underscores around FILE.  The same is
> true with LINE, FUNCTION, etc.


5.) dirname() gives you the full path on disk, not the URL. Usually you can
just remove the document root path to get the URL. This could be in
$_SERVER['DOCUMENT_ROOT'] but you can't rely on that between servers or when
the config changes.
-Stuart

-- 
http://stut.net/


Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 08:53, Daniel Brown  wrote:
>
>    Then you'll be happy with the advent of PHP6:
>
>        http://php.net/goto

Uhh yeah, and 5.3 before that even.  Duh.

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] include question

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 08:53, Stuart  wrote:
>>
>>        1.) We use regular open tags to be compatible with all stock
>> PHP configurations.
>>        2.) We echo out the response from dirname() so that it's
>> output to the HTML source.
>>        3.) We use dirname() twice, so it gives the dirname() of the
>> dirname(), rather than '..'.
>>        4.) There are double underscores around FILE.  The same is
>> true with LINE, FUNCTION, etc.
>
> 5.) dirname() gives you the full path on disk, not the URL. Usually you can
> just remove the document root path to get the URL. This could be in
> $_SERVER['DOCUMENT_ROOT'] but you can't rely on that between servers or when
> the config changes.

6.) When used in conjunction with realpath()[1], it will
resolve the absolute local pathname.

^1: http://php.net/realpath

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 09:15, Robert Cummings  wrote:
>
> I remember the internals debate about 2 or 3 years ago. I was on the pro
> goto side... it does have uses when used properly.

I wholeheartedly concur.  The first programming language I taught
myself was BASIC about 23 years ago.  We may never see the inclusion
of GOSUB in PHP, but GOTO is certainly worthwhile.


Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
 Talk about fond memories.

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 8:19 AM, Daniel Brown  wrote:
> On Fri, Mar 6, 2009 at 09:15, Robert Cummings  wrote:
>>
>> I remember the internals debate about 2 or 3 years ago. I was on the pro
>> goto side... it does have uses when used properly.
>
>    I wholeheartedly concur.  The first programming language I taught
> myself was BASIC about 23 years ago.  We may never see the inclusion
> of GOSUB in PHP, but GOTO is certainly worthwhile.
>
>
>    Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
>  Talk about fond memories.

QuickBasic (actually QBasic, and then later QuickBasic when my mom
shelled out the money for me to buy it) was my first language. I
remember being completely flabbergasted when I found out they packaged
an interpreter with DOS, and it had been under my nose the whole time.
I think my first "finished" program was a D&D character generator.
Basically, just colored and formatted text with the output of 6 or so
random number generations.

Meemorees... :D


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Robert Cummings
On Fri, 2009-03-06 at 08:38 -0600, haliphax wrote:
> On Fri, Mar 6, 2009 at 8:19 AM, Daniel Brown  wrote:
> > On Fri, Mar 6, 2009 at 09:15, Robert Cummings  wrote:
> >>
> >> I remember the internals debate about 2 or 3 years ago. I was on the pro
> >> goto side... it does have uses when used properly.
> >
> >I wholeheartedly concur.  The first programming language I taught
> > myself was BASIC about 23 years ago.  We may never see the inclusion
> > of GOSUB in PHP, but GOTO is certainly worthwhile.
> >
> >
> >Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
> >  Talk about fond memories.
> 
> QuickBasic (actually QBasic, and then later QuickBasic when my mom
> shelled out the money for me to buy it) was my first language. I
> remember being completely flabbergasted when I found out they packaged
> an interpreter with DOS, and it had been under my nose the whole time.
> I think my first "finished" program was a D&D character generator.
> Basically, just colored and formatted text with the output of 6 or so
> random number generations.
> 
> Meemorees... :D

I did Basic on the TRS-80 and saved my programs to a big clunky audio
tape drive... 1... 2... 3... queue Tedd with rocks :)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 8:46 AM, Robert Cummings  wrote:
> On Fri, 2009-03-06 at 08:38 -0600, haliphax wrote:
>> On Fri, Mar 6, 2009 at 8:19 AM, Daniel Brown  wrote:
>> > On Fri, Mar 6, 2009 at 09:15, Robert Cummings  wrote:
>> >>
>> >> I remember the internals debate about 2 or 3 years ago. I was on the pro
>> >> goto side... it does have uses when used properly.
>> >
>> >    I wholeheartedly concur.  The first programming language I taught
>> > myself was BASIC about 23 years ago.  We may never see the inclusion
>> > of GOSUB in PHP, but GOTO is certainly worthwhile.
>> >
>> >
>> >    Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
>> >  Talk about fond memories.
>>
>> QuickBasic (actually QBasic, and then later QuickBasic when my mom
>> shelled out the money for me to buy it) was my first language. I
>> remember being completely flabbergasted when I found out they packaged
>> an interpreter with DOS, and it had been under my nose the whole time.
>> I think my first "finished" program was a D&D character generator.
>> Basically, just colored and formatted text with the output of 6 or so
>> random number generations.
>>
>> Meemorees... :D
>
> I did Basic on the TRS-80 and saved my programs to a big clunky audio
> tape drive... 1... 2... 3... queue Tedd with rocks :)

Oh, I'm not even trying to pretend like I'm half as old as some on
this list. I still chew my own food, thank you very much. ;)

(All in jest, of course... But some of you are pretty old. Ha!)


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Robert Cummings
On Fri, 2009-03-06 at 08:54 -0500, Daniel Brown wrote:
> On Fri, Mar 6, 2009 at 08:53, Daniel Brown  wrote:
> >
> >Then you'll be happy with the advent of PHP6:
> >
> >http://php.net/goto
> 
> Uhh yeah, and 5.3 before that even.  Duh.

I remember the internals debate about 2 or 3 years ago. I was on the pro
goto side... it does have uses when used properly.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Robert Cummings
On Fri, 2009-03-06 at 08:51 -0600, haliphax wrote:
> On Fri, Mar 6, 2009 at 8:46 AM, Robert Cummings  wrote:
> > On Fri, 2009-03-06 at 08:38 -0600, haliphax wrote:
> >> On Fri, Mar 6, 2009 at 8:19 AM, Daniel Brown  wrote:
> >> > On Fri, Mar 6, 2009 at 09:15, Robert Cummings  
> >> > wrote:
> >> >>
> >> >> I remember the internals debate about 2 or 3 years ago. I was on the pro
> >> >> goto side... it does have uses when used properly.
> >> >
> >> >I wholeheartedly concur.  The first programming language I taught
> >> > myself was BASIC about 23 years ago.  We may never see the inclusion
> >> > of GOSUB in PHP, but GOTO is certainly worthwhile.
> >> >
> >> >
> >> >Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
> >> >  Talk about fond memories.
> >>
> >> QuickBasic (actually QBasic, and then later QuickBasic when my mom
> >> shelled out the money for me to buy it) was my first language. I
> >> remember being completely flabbergasted when I found out they packaged
> >> an interpreter with DOS, and it had been under my nose the whole time.
> >> I think my first "finished" program was a D&D character generator.
> >> Basically, just colored and formatted text with the output of 6 or so
> >> random number generations.
> >>
> >> Meemorees... :D
> >
> > I did Basic on the TRS-80 and saved my programs to a big clunky audio
> > tape drive... 1... 2... 3... queue Tedd with rocks :)
> 
> Oh, I'm not even trying to pretend like I'm half as old as some on
> this list. I still chew my own food, thank you very much. ;)
> 
> (All in jest, of course... But some of you are pretty old. Ha!)

I just turned 35... today... that's young by the standards of a 70 year
old >:)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 8:56 AM, Robert Cummings  wrote:
> On Fri, 2009-03-06 at 08:51 -0600, haliphax wrote:
>> On Fri, Mar 6, 2009 at 8:46 AM, Robert Cummings  wrote:
>> > On Fri, 2009-03-06 at 08:38 -0600, haliphax wrote:
>> >> On Fri, Mar 6, 2009 at 8:19 AM, Daniel Brown  wrote:
>> >> > On Fri, Mar 6, 2009 at 09:15, Robert Cummings  
>> >> > wrote:
>> >> >>
>> >> >> I remember the internals debate about 2 or 3 years ago. I was on the 
>> >> >> pro
>> >> >> goto side... it does have uses when used properly.
>> >> >
>> >> >    I wholeheartedly concur.  The first programming language I taught
>> >> > myself was BASIC about 23 years ago.  We may never see the inclusion
>> >> > of GOSUB in PHP, but GOTO is certainly worthwhile.
>> >> >
>> >> >
>> >> >    Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
>> >> >  Talk about fond memories.
>> >>
>> >> QuickBasic (actually QBasic, and then later QuickBasic when my mom
>> >> shelled out the money for me to buy it) was my first language. I
>> >> remember being completely flabbergasted when I found out they packaged
>> >> an interpreter with DOS, and it had been under my nose the whole time.
>> >> I think my first "finished" program was a D&D character generator.
>> >> Basically, just colored and formatted text with the output of 6 or so
>> >> random number generations.
>> >>
>> >> Meemorees... :D
>> >
>> > I did Basic on the TRS-80 and saved my programs to a big clunky audio
>> > tape drive... 1... 2... 3... queue Tedd with rocks :)
>>
>> Oh, I'm not even trying to pretend like I'm half as old as some on
>> this list. I still chew my own food, thank you very much. ;)
>>
>> (All in jest, of course... But some of you are pretty old. Ha!)
>
> I just turned 35... today... that's young by the standards of a 70 year
> old >:)

Well, I may not be decrepit just yet, but I am by no means a
whippersnapper anymore. Looking at turning 27 this April. I'm sure
some of the more geriatric people in the world still consider me a
kid, but I can look at teenagers now and think, "What the hell are
they doing that for?"


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Stuart
2009/3/6 Robert Cummings 

> I just turned 35... today... that's young by the standards of a 70 year
> old >:)


 Happy Birthday ya wise old git.

I started with BBC Basic, moved on to gwbasic then to C, and the rest, as
they say, is history.

First program I ever wrote was a game called Spider. I created person and
spider characters (as in patching over existing letters in the standard
character set), put them on a playing surface and the spider tried to catch
the person as they moved around to pick up asterisks. Really simple but huge
fun. I was hooked. Still am.

-Stuart

-- 
http://stut.net/


Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 9:08 AM, Stuart  wrote:
> 2009/3/6 Robert Cummings 
>>
>> I just turned 35... today... that's young by the standards of a 70 year
>> old >:)
>
>  Happy Birthday ya wise old git.
> I started with BBC Basic, moved on to gwbasic then to C, and the rest, as
> they say, is history.
> First program I ever wrote was a game called Spider. I created person and
> spider characters (as in patching over existing letters in the standard
> character set), put them on a playing surface and the spider tried to catch
> the person as they moved around to pick up asterisks. Really simple but huge
> fun. I was hooked. Still am.

Is that sort of like Robots, where you try to rescue all the humans,
and the robots take a step towards you every time you move? That was
my first TI-BASIC program, though I wrote it admittedly just two years
ago when I should have been paying attention in Accounting II. :D


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Shawn McKenzie
Dollah Ihsan wrote:
> I'm sorry if this is not what you're talking about...
> 
> /**
>  * assume your table structure just like this.
>  * table: users
>  * |  id  |   country| name   |  population |
>  * --
>  * |  1   |Texas |  Fort Worth  |40|
>  *
>  */
> 

Woo hooo!  Did we finally suceed from the union that's going to
socialist shit?  Are we once again the great Republic of Texas!

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] include question

2009-03-06 Thread PJ
Daniel Brown wrote:
> On Fri, Mar 6, 2009 at 08:53, Stuart  wrote:
>   
>>>1.) We use regular open tags to be compatible with all stock
>>> PHP configurations.
>>>2.) We echo out the response from dirname() so that it's
>>> output to the HTML source.
>>>3.) We use dirname() twice, so it gives the dirname() of the
>>> dirname(), rather than '..'.
>>>4.) There are double underscores around FILE.  The same is
>>> true with LINE, FUNCTION, etc.
>>>   
>> 5.) dirname() gives you the full path on disk, not the URL. Usually you can
>> just remove the document root path to get the URL. This could be in
>> $_SERVER['DOCUMENT_ROOT'] but you can't rely on that between servers or when
>> the config changes.
>> 
>
> 6.) When used in conjunction with realpath()[1], it will
> resolve the absolute local pathname.
>
> ^1: http://php.net/realpath
>
>   
Sorry, guys, but none of this works...
I get the document root which is wonderful but it misses the vhost root
completely.
So what I get both with realpath and $SERVER['DOCUMENT_ROOT']is
/usr/local/www/apache22/data/images/file.gif or
/usr/local/www/apache22/data/../images/file.gif
and that, of course misses the main directory for this site which is
ptahhotep

In /ptahhotep/file.php - the path for the image.gif is images/image.gif
In /ptahhotep/admin/another_file.php/ the path  for the image.gif is
../images/image.gif

But as I try different variations, I finally see that adding the root
directory name for the site does the trick.

Have I discovered something new here? :-)


-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread PJ
Robert Cummings wrote:
> On Fri, 2009-03-06 at 08:51 -0600, haliphax wrote:
>   
>> On Fri, Mar 6, 2009 at 8:46 AM, Robert Cummings  wrote:
>> 
>>> On Fri, 2009-03-06 at 08:38 -0600, haliphax wrote:
>>>   
 On Fri, Mar 6, 2009 at 8:19 AM, Daniel Brown  wrote:
 
> On Fri, Mar 6, 2009 at 09:15, Robert Cummings  
> wrote:
>   
>> I remember the internals debate about 2 or 3 years ago. I was on the pro
>> goto side... it does have uses when used properly.
>> 
>I wholeheartedly concur.  The first programming language I taught
> myself was BASIC about 23 years ago.  We may never see the inclusion
> of GOSUB in PHP, but GOTO is certainly worthwhile.
>
>
>Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
>  Talk about fond memories.
>   
 QuickBasic (actually QBasic, and then later QuickBasic when my mom
 shelled out the money for me to buy it) was my first language. I
 remember being completely flabbergasted when I found out they packaged
 an interpreter with DOS, and it had been under my nose the whole time.
 I think my first "finished" program was a D&D character generator.
 Basically, just colored and formatted text with the output of 6 or so
 random number generations.

 Meemorees... :D
 
>>> I did Basic on the TRS-80 and saved my programs to a big clunky audio
>>> tape drive... 1... 2... 3... queue Tedd with rocks :)
>>>   
>> Oh, I'm not even trying to pretend like I'm half as old as some on
>> this list. I still chew my own food, thank you very much. ;)
>>
>> (All in jest, of course... But some of you are pretty old. Ha!)
>> 
>
> I just turned 35... today... that's young by the standards of a 70 year
> old >:)
>
> Cheers,
> Rob.
>   
Yeah... wet behind the ears... heh...heh...heh :-P

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread PJ
Shawn McKenzie wrote:
> Dollah Ihsan wrote:
>   
>> I'm sorry if this is not what you're talking about...
>>
>> /**
>>  * assume your table structure just like this.
>>  * table: users
>>  * |  id  |   country| name   |  population |
>>  * --
>>  * |  1   |Texas |  Fort Worth  |40|
>>  *
>>  */
>>
>> 
>
> Woo hooo!  Did we finally suceed from the union that's going to
> socialist shit?  Are we once again the great Republic of Texas!
>
>   
Oowooo watch that socialist shit... it may the only
thing that will save us from the ooze we're into bacause of the "old
ways" of W and the rest of the greedy and warmongering bastards of our
recent past.
But, then, we're going to fix all the shit with money from the taxpayers
to glorify the exploits of the very crooks who fucked us in the first
place... we just don't learn from the past, do we? Don't worry as we
trapse along, we'll just hang ourselves again and again...

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Stuart
2009/3/6 haliphax 

> On Fri, Mar 6, 2009 at 9:08 AM, Stuart  wrote:
> > 2009/3/6 Robert Cummings 
> >>
> >> I just turned 35... today... that's young by the standards of a 70 year
> >> old >:)
> >
> >  Happy Birthday ya wise old git.
> > I started with BBC Basic, moved on to gwbasic then to C, and the rest, as
> > they say, is history.
> > First program I ever wrote was a game called Spider. I created person and
> > spider characters (as in patching over existing letters in the standard
> > character set), put them on a playing surface and the spider tried to
> catch
> > the person as they moved around to pick up asterisks. Really simple but
> huge
> > fun. I was hooked. Still am.
>
> Is that sort of like Robots, where you try to rescue all the humans,
> and the robots take a step towards you every time you move? That was
> my first TI-BASIC program, though I wrote it admittedly just two years
> ago when I should have been paying attention in Accounting II. :D


Sounds similar. My Mum was afraid of spiders and being 8 years old I made
something I thought would freak her out. In my recollection it did but
thinking about it I'm sure she was just humouring me.

-Stuart

-- 
http://stut.net/


Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Jochem Maas
Anton Heuschen schreef:
> This might sound trivial, but for the live of me cant seem to get it to
> work, and I am not familiar with such a thing.

seems like you've done your best to make it sound as confusing as possible,
this happens sometimes when you no longer see the wood for the trees :-)

> 
> What I have is a query lets say :
> 
> select  country,name,population from USERS where id= 'some_id' ";
> 

'USERS' seems like an odd namew for the table in question.

> 
> Now I want to assign the result to one set (The above example might have 3+
> entries per telephone, thus what would be nice is something like an array of

per telephone? where do these telephones come from? is that a freudian slip?
did the phone ring whilst you we're writing that sentence?

keep reading ... it gets more php related as we go one ...

> :
> 
> 
> [id][country][name]  = population .. or to be exact if I echo the
> value for each id and country and name to get the population value
> 
> 
> Like :
> 
> Array {
> 
>   [id] array {
>  [country] array {
> [0] = USA
>   }
>   [name] array {
>  [0] = test
> 
>   }
> 
> }
> 

I'm not grokking that array structure much.

> 
> 
> 
> I dont know something like that, maybe Im over comlicating the question now
> even, the main thing is wondered was in the first place was with a standard
> query and variable assign, from the query like:
> 
> select  country,name,population from USERS where id= 'some_id' ";
> 
> normally you would just assign each field to one variable. like
> 
> $country = result["country"]
> $name = result["name"]

sidenote: I never see the point of assign the vars like that anyhow, why not 
just use
$result['name'] and do away with the exytra $name var?

> 
> 
> But now I want all 3 fields as one variable (which would be an array) ..but
> how ?

why? I'd guess it's because you want to do a 'look-up' of the data, that
would suggest you don't want to be extracting the data on a row by row basis,
but rather grab all the data and parse it into a format you can use for
multiple look ups, here's a little class idea,maybe it offers some
inspiration/insight/relief (it untested because I can't be bothered to setup a 
DB):

abstract class Populations
{
static function getAll($type = null)
{
self::init();

if ($type) {
return isset(self::$data[$type]) ? self::$data[$type] : 
null;
}   

return self::$data;
}

static function byId($id)
{
return self::get('names', intval($id));
}

static function byPlaceName($name)
{
return self::get('names', strtolower(trim($name)));
}

static function byCountryName($name)
{
return self::get('countries', strtolower(trim($name)));
}

static private function get($k, $v)
{
self::init();

if (isset(self::$data[$k][$v]))
return self::$data[$k][$v];

return null;
}

private static function init()
{
if (!isset(self::$data))
self::loadData();
}

private static function loadData()
{
self::$data = array(
'ids'   => array(),
'names' => array(),
'countries' => array(),
);

// let's assume that the following query will only return
// a reasonable number of rows (i.e. not a very large number)

// let's also assume that a db connection has been setup

$res = mysql_query('SELECT id, country, name, population FROM 
users');

if ($res && mysql_num_rows($res)) {
while ($row = mysql_fetch_assoc($res)) {
$i = $row['id'];
$n = strtolower(trim($row['name']));
$c = strtolower(trim($row['country']));

self::$data['ids'][$i]   =
self::$data['names'][$n] = $row['population'];

if (!isset(self::$data['countries'][$c]))
self::$data['countries'][$c] = 0;

self::$data['countries'][$c] += 
$row['population'];
}
}   
}
}

you would use this class something like:

echo Population::byId(1), "\n";
echo Population::byPlaceName("Texas"), "\n";
echo Population::byCountryName("USA"), "\n";

var_dump(Population::getAll("names"));
var_dump(Population::getAll());


> 
> I hope I have not totally confused the question now.

if you didn'

Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Jochem Maas
PJ schreef:
> Shawn McKenzie wrote:
>> Dollah Ihsan wrote:
>>   
>>> I'm sorry if this is not what you're talking about...
>>>
>>> /**
>>>  * assume your table structure just like this.
>>>  * table: users
>>>  * |  id  |   country| name   |  population |
>>>  * --
>>>  * |  1   |Texas |  Fort Worth  |40|
>>>  *
>>>  */
>>>
>>> 
>> Woo hooo!  Did we finally suceed from the union that's going to
>> socialist shit?  Are we once again the great Republic of Texas!
>>
>>   
> Oowooo watch that socialist shit... it may the only
> thing that will save us from the ooze we're into bacause of the "old
> ways" of W and the rest of the greedy and warmongering bastards of our
> recent past.
> But, then, we're going to fix all the shit with money from the taxpayers
> to glorify the exploits of the very crooks who fucked us in the first
> place... we just don't learn from the past, do we? Don't worry as we
> trapse along, we'll just hang ourselves again and again...

Dubya is a stinking socialist though ... no I don't grok that either.

Hey Wait. let's kill this thread before someone gets hurt.

> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Michael A. Peters

Anton Heuschen wrote:

This might sound trivial, but for the live of me cant seem to get it to
work, and I am not familiar with such a thing.

What I have is a query lets say :

select  country,name,population from USERS where id= 'some_id' ";


Now I want to assign the result to one set (The above example might have 3+
entries per telephone, thus what would be nice is something like an array of
:


[id][country][name]  = population .. or to be exact if I echo the
value for each id and country and name to get the population value


Like :

Array {

  [id] array {
 [country] array {
[0] = USA
  }
  [name] array {
 [0] = test

  }

}




I dont know something like that, maybe Im over comlicating the question now
even, the main thing is wondered was in the first place was with a standard
query and variable assign, from the query like:

select  country,name,population from USERS where id= 'some_id' ";

normally you would just assign each field to one variable. like

$country = result["country"]
$name = result["name"]


But now I want all 3 fields as one variable (which would be an array) ..but
how ?

I hope I have not totally confused the question now.

Thanks in advance



not sure if this is what you want - but

$sql="your query";
$result=mysql_query;
while ($foo = mysql_fetch_array($result)) {
   $bar[]=$foo;
   }

then -
$bar[0]['country']
$bar[0]['name']
$bar[0]['population']

would represent one row of your query

$bar[1]['country']
$bar[1]['name']
$bar[1]['population']

would represent another row of your query

etc.

Is that what you are looking for?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Assign 2 values from Mysql to an array

2009-03-06 Thread Jim Lucas
I will take theirs and modify it just a little more to create the print_r() 
output that the OP suggested.

function getPopulationById($id) {
$dataSet = array();
if ( ( $result = mysql_query('SELECT country, name, population FROM 
users WHERE id = ' . $id) !== false ) {
while ( $row = mysql_fetch_assoc($result) ) {
$dataSet[$id] = $row;
}
}
return $dataSet;
}

This will return:

Array {
[id] array {
[country] = USA
[name] = test
[population] = 123
}
}


OPs way would result in a layout like the following...

Array {
[id] array {
[country] = array
[0] = USA
}
[name] = array
[0] = test
}
[population] = array
[0] = 123
}
}
}


I don't see a reason why the OP was suggesting that he do it this way...  I 
can't see the reason for the extra nested array for the final country,
name, and population values.  Should be the value, nothing more.

Chetan Rane wrote:
> Hi this is similar to what Dollah Ihsan had suggested , however I ave
> tweeked the getPopulationById function a bit.
> /**
>  * assume your table structure just like this.
>  * table: users
>  * |  id  |   country| name   |  population |
>  * --
>  * |  1   |Texas |  Fort Worth  |40|
>  *
>  */
> 
> function getPopulationById($id) {
>   // echo 'SELECT country, name, population FROM users WHERE id = ' .
> $id;die;
>   $result = mysql_query('SELECT country, name, population FROM users
> WHERE id = ' . $id);
>   While($row = mysql_fetch_assoc($result)) 
>   $pop[$id][$row['country']][$row['name']] =
> $row['population'];
>   return $pop;
> }
> 
> 
> Chetan Dattaram Rane | Software Engineer | Persistent Systems
> chetan_r...@persistent.co.in  | Cell: +91 94033 66714 | Tel: +91 (0832) 30
> 79014
> Innovation in software product design, development and delivery-
> www.persistentsys.com
> 
> 
> 
> 
> -Original Message-
> From: Dollah Ihsan [mailto:dollah.ih...@gmail.com] 
> Sent: Friday, March 06, 2009 3:04 PM
> To: Anton Heuschen
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] Assign 2 values from Mysql to an array
> 
> I'm sorry if this is not what you're talking about...
> 
> /**
>  * assume your table structure just like this.
>  * table: users
>  * |  id  |   country| name   |  population |
>  * --
>  * |  1   |Texas |  Fort Worth  |40|
>  *
>  */
> 
> function getPopulationById($id) {
>   // echo 'SELECT country, name, population FROM users WHERE id = ' .
> $id;die;
>   $result = mysql_query('SELECT country, name, population FROM users
> WHERE id = ' . $id);
>   if(mysql_num_rows($result) != 1) return false;
>   $row = mysql_fetch_assoc($result);
>   $pop[$id][$row['country']][$row['name']] = $row['population'];
>   return $pop;
> }
> 
> $array = getPopulationById(1);
> print_r($array);
> // print_r($array) should be like this:
> // Array ( [1] => Array ( [Texas] => Array ( [Fort Worth] => 40 ) ) )
> 
> On Fri, Mar 6, 2009 at 3:41 PM, Anton Heuschen  wrote:
>> This might sound trivial, but for the live of me cant seem to get it to
>> work, and I am not familiar with such a thing.
>>
>> What I have is a query lets say :
>>
>> select  country,name,population from USERS where id= 'some_id' ";
>>
>>
>> Now I want to assign the result to one set (The above example might have
> 3+
>> entries per telephone, thus what would be nice is something like an array
> of
>> :
>>
>>
>> [id][country][name]  = population .. or to be exact if I echo the
>> value for each id and country and name to get the population value
>>
>>
>> Like :
>>
>> Array {
>>
>>  [id] array {
>> [country] array {
>>[0] = USA
>>  }
>>  [name] array {
>> [0] = test
>>
>>  }
>>
>> }
>>
>>
>>
>>
>> I dont know something like that, maybe Im over comlicating the question
> now
>> even, the main thing is wondered was in the first place was with a
> standard
>> query and variable assign, from the query like:
>>
>> select  country,name,population from USERS where id= 'some_id' ";
>>
>> normally you would just assign each field to one variable. like
>>
>> $country = result["country"]
>> $name = result["name"]
>>
>>
>> But now I want all 3 fields as one variable (which would be an array)
> ..but
>> how ?
>>
>> I hope I have not totally confused the question now.
>>
>> Thanks in advance
> 


-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
  

[PHP] verify another flavor

2009-03-06 Thread PJ
I know I'm a pain the butt but I just can't help asking for help. You
guys are so nice... ;-)
I am trying to do some checks if there are entries in the db so I can
then insert the right stuff. And I'm looking for ways to simplify things.
I probably dont understand the flow of things here, but this almost
works. :-\
$Author = $first_nameIN . ' ' . $last_nameIN;
echo $Author;
$sql1 = "SELECT CONCAT_WS(" ", first_name, last_name) as Author FROM
author WHERE Author LIKE '$Author'";
  $result1 = mysql_query($sql1);
this would be instead of
$sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name
LIKE 'first_nameIN' && last_nameIN LIKE 'last_nameIN')"

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] verify another flavor

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 10:36 AM, PJ  wrote:
> I know I'm a pain the butt but I just can't help asking for help. You
> guys are so nice... ;-)
> I am trying to do some checks if there are entries in the db so I can
> then insert the right stuff. And I'm looking for ways to simplify things.
> I probably dont understand the flow of things here, but this almost
> works. :-\
> $Author = $first_nameIN . ' ' . $last_nameIN;
> echo $Author;
> $sql1 = "SELECT CONCAT_WS(" ", first_name, last_name) as Author FROM
> author     WHERE Author LIKE '$Author'";
>          $result1 = mysql_query($sql1);
> this would be instead of
> $sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name
> LIKE 'first_nameIN' && last_nameIN LIKE 'last_nameIN')"

Personally, I would avoid using the CONCAT_WS() MySQL function in your
query, since you're just checking for existence rather than inserting
records (for efficiency and scalability's sake). Also--why are you
using LIKE if you're checking for a particular first and last name?
Why not just use the equality operator (=)? And... be careful
alternating quote styles in your SQL statements. The double-quotes ("
") following CONCAT_WS( will end your string.

Also... I may be wholly wrong on this one, but I'm not sure MySQL uses
C-style syntax for comparisons (&&, ||, !=) but rather "BASIC-style"
syntax (AND, OR, NOT/<>). Again, I'm not sure about this. Maybe that
part works just fine.

I would go about it like this:

$sql1 = "select concat_ws(' ', first_name, last_name) as Author_Name
from author where first_name = '$first_nameIN' and last_name =
'$last_nameIN'";

You still get your pretty output (concatenated first and last name),
but you're checking the indexed columns individually rather than
combining them first, like you did in your second statement. However,
in your second statement, you did not prefix your PHP variable names
with $, so you were literally checking against the strings
'first_nameIN' and 'last_nameIN'.

Hope this helps,


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] verify another flavor

2009-03-06 Thread Bastien Koert
$sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name
LIKE 'first_nameIN' && last_nameIN LIKE 'last_nameIN')"

On Fri, Mar 6, 2009 at 11:36 AM, PJ  wrote:

> I know I'm a pain the butt but I just can't help asking for help. You
> guys are so nice... ;-)
> I am trying to do some checks if there are entries in the db so I can
> then insert the right stuff. And I'm looking for ways to simplify things.
> I probably dont understand the flow of things here, but this almost
> works. :-\
> $Author = $first_nameIN . ' ' . $last_nameIN;
> echo $Author;
> $sql1 = "SELECT CONCAT_WS(" ", first_name, last_name) as Author FROM
> author WHERE Author LIKE '$Author'";
>  $result1 = mysql_query($sql1);
> this would be instead of
> $sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name
> LIKE 'first_nameIN' && last_nameIN LIKE 'last_nameIN')"
>
> --
> unheralded genius: "A clean desk is the sign of a dull mind. "
> -
> Phil Jourdan --- p...@ptahhotep.com
>   http://www.ptahhotep.com
>   http://www.chiccantine.com/andypantry.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
You  need the % operator for a like comparison

$sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name
LIKE '%first_nameIN%' && last_nameIN LIKE '%last_nameIN%')"


but most likely, you really want a true comparison to see if that user
exists

$sql1 = "SELECT first_name, last_name) FROM author WHERE (first_name
= 'first_nameIN' && last_nameIN = 'last_nameIN')"

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Conclusion of "use strict"...

2009-03-06 Thread Jochem Maas
Hans Schultz schreef:
> Hehe,
> 
> I don't agree with either :-)
> 
> But I am still searching for some solution, and when (and if) I find it
> I will be happy to share with you (btw, obviously nobody shared
> experiences about that compiler)
> 

no, but did the comments I made about var vars and vars included via other
[optional files] register?

also you might consider something low key as a starting point, here's
a handy little oneliner for the [bash] shell:

find . -name \*.php \! -exec php -d error_reporting=4095 -d display_errors=1 -l 
{} \;

> 
> Hans is the OP, the one you thought "got it all wrong.", you're
> actually
> agree with me ... which is as natural as it is inevitable ;-)
> 
> LOL, right  :)
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Hi lista,

I have been trying to figure this out for the last couple of hours but I'm
lack of luck.
Take a look at these regex's, the string that was inputed into the
preg_replace (using Uis modificators) and the results:
(the lists have correspondence to each other)

ORIGINAL STRING


http://www.zshare.net/video/541070871c7a8d9c
http://www.guba.com/watch/2000821351
http://www.veoh.com/videos/v4609719YfsCFpf


REGEX USED (with Uis modificators)

http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)

THE RETURNED STRING

41070871c7a8d9c
000821351
4609719YfsCFpf

If you will go through this carefully you will notice that the first
character of each matching group is being deleted.
The regex's and the replacements string are being fetched from the database
(mysql) and goes straight to the preg_replace function with the original
string.

I have no idea why this happens.
I'm looking forward for your opinions and suggestions.

Regards,
Nitsan


Re: [PHP] Re: Intermittent problem sending mail with PHP

2009-03-06 Thread Stephen Hutchison

thanks Jim - I change over to SwiftMailer and its working well.

"Jim Lucas"  wrote in message 
news:49ae0375.2040...@cmsws.com...

Stephen Hutchison wrote:
I'll check with my ISP but if is that then it's a very low limit. I'm 
finding it's only allowing two or three through before hanging.


Is there something i can put in my code so that it at least fails 
gracefully? It's not a good look just hanging like that.


Thanks
Stephen


"Chris"  wrote in message 
news:49ada6ab.5060...@gmail.com...

Stephen Hutchison wrote:
This appears to by a problem with the mail function. When I comment out 
the lines:

if (mail($recipient, $subject, $message, $headers))
   echo 'Succeeded';
   else
   echo 'Error - please check your e-mail address';


More likely a mail server issue rather than the mail function itself.

Do they have any restrictions on how often you can send email? (Some 
hosts only let you send say 50 emails an hour).


Log everything you're trying to do in php (log when it works, when it 
doesn't) and include a timestamp - then get your host to look at their 
mail server logs for the failure times and see what shows up.


--
Postgresql & php tutorials
http://www.designmagick.com/






I would recommend getting away from using the mail() function altogether.

I would look into using something like phpmailer or SwiftMailer.

They are SMTP mail classes that let you build and email and send it 
directly to your SMTP server.


Also allows you to log into the mail server with a valid email account and 
send using that account.


That last part might get you around the X/minute email limit or whatever 
else it might be. 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Syntax checker? Character replacing

2009-03-06 Thread Terion Miller
I have this and think maybe something is off, because if there is an amp (&)
in the location then it only displays a comma , and nothing else:

if (isset($_SERVER['QUERY_STRING'])) {$Page .= ($_SERVER['QUERY_STRING']?
'?'. str_replace("&","&",$_SERVER['QUERY_STRING']) : '');}


is that wrong?


Re: [PHP] Syntax checker? Character replacing

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 2:05 PM, Terion Miller  wrote:
> I have this and think maybe something is off, because if there is an amp (&)
> in the location then it only displays a comma , and nothing else:
>
> if (isset($_SERVER['QUERY_STRING'])) {$Page .= ($_SERVER['QUERY_STRING']?
> '?'. str_replace("&","&",$_SERVER['QUERY_STRING']) : '');}
>
>
> is that wrong?

It looks alright to me, but I don't see the need for the in-line
conditional statement since you've already run isset() on
$_SERVER['QUERY_STRING']. Simplify your code:

if(isset($_SERVER['QUERY_STRING']))
$Page .= str_replace('&', '&', $_SERVER['QUERY_STRING']);

Does that do the trick?


-- 
// Todd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Adam
would this not work? :

http://www.zshare.net/video/541070871c7a8d9c";;
$replaceWithThis = 'HELLYES-';

echo $string."\n";
echo preg_replace('/\S+video\//',$replaceWithThis,$string)."\n";
echo $replaceWithThis.substr($string, strripos($string, '/')+1,
strlen($string))."\n";
echo $replaceWithThis.substr(strrchr($string, '/'), 1,
strlen(strrchr($string, '/')));


?>

OUTPUT:

C:\>php test.php
http://www.zshare.net/video/541070871c7a8d9c
HELLYES-541070871c7a8d9c
HELLYES-541070871c7a8d9c
HELLYES-541070871c7a8d9c
C:\>

On Fri, Mar 6, 2009 at 2:32 PM, Nitsan Bin-Nun  wrote:
> Hi lista,
>
> I have been trying to figure this out for the last couple of hours but I'm
> lack of luck.
> Take a look at these regex's, the string that was inputed into the
> preg_replace (using Uis modificators) and the results:
> (the lists have correspondence to each other)
>
> ORIGINAL STRING
> 
>
> http://www.zshare.net/video/541070871c7a8d9c
> http://www.guba.com/watch/2000821351
> http://www.veoh.com/videos/v4609719YfsCFpf
>
>
> REGEX USED (with Uis modificators)
> 
> http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)               $3
> http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)              $3
> http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
>
> THE RETURNED STRING
> 
> 41070871c7a8d9c
> 000821351
> 4609719YfsCFpf
>
> If you will go through this carefully you will notice that the first
> character of each matching group is being deleted.
> The regex's and the replacements string are being fetched from the database
> (mysql) and goes straight to the preg_replace function with the original
> string.
>
> I have no idea why this happens.
> I'm looking forward for your opinions and suggestions.
>
> Regards,
> Nitsan
>



-- 
Adi...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Haven't tested your code but from a rapid look it would work.

The issue here is that I don't understand why my expression doesn't catches
the full match and emits the first character?

On Fri, Mar 6, 2009 at 10:17 PM, Adam  wrote:

> would this not work? :
>
> 
> $string = "http://www.zshare.net/video/541070871c7a8d9c";;
> $replaceWithThis = 'HELLYES-';
>
> echo $string."\n";
> echo preg_replace('/\S+video\//',$replaceWithThis,$string)."\n";
> echo $replaceWithThis.substr($string, strripos($string, '/')+1,
> strlen($string))."\n";
> echo $replaceWithThis.substr(strrchr($string, '/'), 1,
> strlen(strrchr($string, '/')));
>
>
> ?>
>
> OUTPUT:
>
> C:\>php test.php
> http://www.zshare.net/video/541070871c7a8d9c
> HELLYES-541070871c7a8d9c
> HELLYES-541070871c7a8d9c
> HELLYES-541070871c7a8d9c
> C:\>
>
> On Fri, Mar 6, 2009 at 2:32 PM, Nitsan Bin-Nun 
> wrote:
> > Hi lista,
> >
> > I have been trying to figure this out for the last couple of hours but
> I'm
> > lack of luck.
> > Take a look at these regex's, the string that was inputed into the
> > preg_replace (using Uis modificators) and the results:
> > (the lists have correspondence to each other)
> >
> > ORIGINAL STRING
> > 
> >
> > http://www.zshare.net/video/541070871c7a8d9c
> > http://www.guba.com/watch/2000821351
> > http://www.veoh.com/videos/v4609719YfsCFpf
> >
> >
> > REGEX USED (with Uis modificators)
> > 
> > http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
> > http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
> > http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
> >
> > THE RETURNED STRING
> > 
> > 41070871c7a8d9c
> > 000821351
> > 4609719YfsCFpf
> >
> > If you will go through this carefully you will notice that the first
> > character of each matching group is being deleted.
> > The regex's and the replacements string are being fetched from the
> database
> > (mysql) and goes straight to the preg_replace function with the original
> > string.
> >
> > I have no idea why this happens.
> > I'm looking forward for your opinions and suggestions.
> >
> > Regards,
> > Nitsan
> >
>
>
>
> --
> Adi...
>


Re: [PHP] Syntax checker? Character replacing

2009-03-06 Thread Adam
just clean up your code and it will work:

http://www.google.ca/search?hl=en&q=php+rocks%21%21%21&meta=';

if (isset($qString))
{
$buffer = str_replace("&","&",$qString);
}

echo $buffer."\n";

?>

OUTPUT:
C:\>php test.php
http://www.google.ca/search?hl=en&q=php+rocks%21%21%21&meta=

C:\>

On Fri, Mar 6, 2009 at 3:05 PM, Terion Miller  wrote:
> I have this and think maybe something is off, because if there is an amp (&)
> in the location then it only displays a comma , and nothing else:
>
> if (isset($_SERVER['QUERY_STRING'])) {$Page .= ($_SERVER['QUERY_STRING']?
> '?'. str_replace("&","&",$_SERVER['QUERY_STRING']) : '');}
>
>
> is that wrong?
>



-- 
Adi...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] insert array values

2009-03-06 Thread PJ
I've been racking my little peanut-brain as well as big Google with
little hope...
I can retrieve the array from the multiple select dropdown box but I
can't quite manage to insert the data which is just id numbers for a table.
I've tried some while stuff but doesn't work. I know I don't have the
right syntax on anything at this point. Here's an effort that doesn' work.
Dont know if I should be using $categoriesIN[] type of stuff...
but my tries were from web illustrations...
the outcommented line returns the values of the array... but how to pass
them to the query?

foreach ($categoriesIN as $category) {
//"$category";
$sql = "INSERT INTO book_categories ( book_id, category )
VALUES( book.id WHERE title = $titleIN, $category )";
$result = mysql_query($query, $db);;
}
TIA

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] include_path

2009-03-06 Thread Eric Lease Morgan

My initial PHP script is not recognizing the values in my include_path. Why?

I compiled and installed PHP yesterday:

  $ php -version
  PHP 5.2.9 (cli) (built: Mar  5 2009 15:33:55)

I then installed a PHP script whose beginning looks like this:

  // Require System Libraries
  require_once 'PEAR.php';
  require_once 'sys/Interface.php';
  require_once 'sys/User.php';

When I fire up this script I get the following error:

  Warning: require_once(Smarty/Smarty.class.php)
  [function.require-once]: failed to open stream: No such file or
  directory in /var/www/html/web/sys/Interface.php on line 21
  
  Fatal error: require_once() [function.require]: Failed opening
  required 'Smarty/Smarty.class.php'
  (include_path='.:/usr/lib/php') in
  /var/www/html/web/sys/Interface.php on line 21

Ironically, Smarty/Smarty.class.php IS located under /usr/lib/php. So is
PEAR.php.

Why can't my PHP script find Smarty/Smarty.class.php when it is located in
my path, especially if it finds PEAR.php? How do I diagnose this problem?

-- 
Eric Lease Morgan
University of Notre Dame


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] include_path

2009-03-06 Thread 9el
On Sat, Mar 7, 2009 at 3:13 AM, Eric Lease Morgan  wrote:

>
> My initial PHP script is not recognizing the values in my include_path.
> Why?
>
> I compiled and installed PHP yesterday:
>
>  $ php -version
>  PHP 5.2.9 (cli) (built: Mar  5 2009 15:33:55)
>
> I then installed a PHP script whose beginning looks like this:
>
>  // Require System Libraries
>  require_once 'PEAR.php';
>  require_once 'sys/Interface.php';
>  require_once 'sys/User.php';
>
> When I fire up this script I get the following error:
>
>  Warning: require_once(Smarty/Smarty.class.php)
>  [function.require-once]: failed to open stream: No such file or
>  directory in /var/www/html/web/sys/Interface.php on line 21
>
>  Fatal error: require_once() [function.require]: Failed opening
>  required 'Smarty/Smarty.class.php'
>  (include_path='.:/usr/lib/php') in
>  /var/www/html/web/sys/Interface.php on line 21
>
> Ironically, Smarty/Smarty.class.php IS located under /usr/lib/php. So is
> PEAR.php.


/usr/lib/php is not in the default scope of webroot  ie. /var/www  :)
You have to allow apache to access  /usr/lib/php location

>
>
> Why can't my PHP script find Smarty/Smarty.class.php when it is located in
> my path, especially if it finds PEAR.php? How do I diagnose this problem?
>
> --
> Eric Lease Morgan
> University of Notre Dame
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] include_path

2009-03-06 Thread Eric Lease Morgan

On 3/6/09 4:19 PM, "9el"  wrote:

>> Ironically, Smarty/Smarty.class.php IS located under /usr/lib/php. So is
>> PEAR.php.
> 
> /usr/lib/php is not in the default scope of webroot  ie. /var/www  :)
> You have to allow apache to access  /usr/lib/php location

Thank you for the prompt reply, and it seems very feasible, but how do I
allow apache access to the /usr/lib/php locatdion?

-- 
Eric Lease Morgan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread Bastien Koert
On Fri, Mar 6, 2009 at 4:00 PM, PJ  wrote:

> I've been racking my little peanut-brain as well as big Google with
> little hope...
> I can retrieve the array from the multiple select dropdown box but I
> can't quite manage to insert the data which is just id numbers for a table.
> I've tried some while stuff but doesn't work. I know I don't have the
> right syntax on anything at this point. Here's an effort that doesn' work.
> Dont know if I should be using $categoriesIN[] type of stuff...
> but my tries were from web illustrations...
> the outcommented line returns the values of the array... but how to pass
> them to the query?
>
> foreach ($categoriesIN as $category) {
>//"$category";
> $sql = "INSERT INTO book_categories ( book_id, category )
>VALUES( book.id WHERE title = $titleIN, $category )";
>$result = mysql_query($query, $db);;
>}
> TIA
>
> --
> unheralded genius: "A clean desk is the sign of a dull mind. "
> -
> Phil Jourdan --- p...@ptahhotep.com
>   http://www.ptahhotep.com
>   http://www.chiccantine.com/andypantry.php
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
As its an array, you could join the data with an IMPLODE into a string, but
does that meet your needs? The other option is to create a sub-table for
this element and insert each item thru a loop individually.

-- 

Bastien

Cat, the other other white meat


Re: [PHP] include_path

2009-03-06 Thread Bastien Koert
On Fri, Mar 6, 2009 at 4:21 PM, Eric Lease Morgan  wrote:

>
> On 3/6/09 4:19 PM, "9el"  wrote:
>
> >> Ironically, Smarty/Smarty.class.php IS located under /usr/lib/php. So is
> >> PEAR.php.
> >
> > /usr/lib/php is not in the default scope of webroot  ie. /var/www  :)
> > You have to allow apache to access  /usr/lib/php location
>
> Thank you for the prompt reply, and it seems very feasible, but how do I
> allow apache access to the /usr/lib/php locatdion?
>
> --
> Eric Lease Morgan
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If the SMARTY call is the same to the same path, should it not be

require_once("Smarty.class.php");

and not

require_once("Smarty/Smarty.class.php");

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Jim Lucas
Nitsan Bin-Nun wrote:
> Hi lista,
> 
> I have been trying to figure this out for the last couple of hours but I'm
> lack of luck.
> Take a look at these regex's, the string that was inputed into the
> preg_replace (using Uis modificators) and the results:
> (the lists have correspondence to each other)
> 
> ORIGINAL STRING
> 
> 
> http://www.zshare.net/video/541070871c7a8d9c
> http://www.guba.com/watch/2000821351
> http://www.veoh.com/videos/v4609719YfsCFpf
> 
> 
> REGEX USED (with Uis modificators)
> 
> http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
> http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
> http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
> 
> THE RETURNED STRING
> 
> 41070871c7a8d9c
> 000821351
> 4609719YfsCFpf
> 
> If you will go through this carefully you will notice that the first
> character of each matching group is being deleted.
> The regex's and the replacements string are being fetched from the database
> (mysql) and goes straight to the preg_replace function with the original
> string.
> 
> I have no idea why this happens.
> I'm looking forward for your opinions and suggestions.
> 
> Regards,
> Nitsan
> 

In my opinion...

http://us3.php.net/parse_url   is your friend here...

http://www.zshare.net/video/541070871c7a8d9c';
$urls[] = 'http://www.guba.com/watch/2000821351';
$urls[] = 'http://www.veoh.com/videos/v4609719YfsCFpf';

$url_paths = array();

foreach ( $urls AS $id => $url ) {
$url_paths[$id] = parse_url($url, PHP_URL_PATH);
}

print_r($url_paths);

foreach ( $url_paths AS $paths ) {
list( , ,$value) = explode('/', $paths, 3);
echo $value;
}

?>

The above outputs the following:



-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Jim Lucas
Jim Lucas wrote:
> Nitsan Bin-Nun wrote:
>> Hi lista,
>>
>> I have been trying to figure this out for the last couple of hours but I'm
>> lack of luck.
>> Take a look at these regex's, the string that was inputed into the
>> preg_replace (using Uis modificators) and the results:
>> (the lists have correspondence to each other)
>>
>> ORIGINAL STRING
>> 
>>
>> http://www.zshare.net/video/541070871c7a8d9c
>> http://www.guba.com/watch/2000821351
>> http://www.veoh.com/videos/v4609719YfsCFpf
>>
>>
>> REGEX USED (with Uis modificators)
>> 
>> http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
>> http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
>> http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
>>
>> THE RETURNED STRING
>> 
>> 41070871c7a8d9c
>> 000821351
>> 4609719YfsCFpf
>>
>> If you will go through this carefully you will notice that the first
>> character of each matching group is being deleted.
>> The regex's and the replacements string are being fetched from the database
>> (mysql) and goes straight to the preg_replace function with the original
>> string.
>>
>> I have no idea why this happens.
>> I'm looking forward for your opinions and suggestions.
>>
>> Regards,
>> Nitsan
>>
> 
> In my opinion...
> 
> http://us3.php.net/parse_url   is your friend here...
> 
>  
> $urls[] = 'http://www.zshare.net/video/541070871c7a8d9c';
> $urls[] = 'http://www.guba.com/watch/2000821351';
> $urls[] = 'http://www.veoh.com/videos/v4609719YfsCFpf';
> 
> $url_paths = array();
> 
> foreach ( $urls AS $id => $url ) {
>   $url_paths[$id] = parse_url($url, PHP_URL_PATH);
> }
> 
> print_r($url_paths);
> 
> foreach ( $url_paths AS $paths ) {
>   list( , ,$value) = explode('/', $paths, 3);
>   echo $value.PHP_EOL;
> }
> 
> ?>
> 
> The above outputs the following:
> 
CTRL - Enter a little quick...

Array
(
[0] => /video/541070871c7a8d9c
[1] => /watch/2000821351
[2] => /videos/v4609719YfsCFpf
)
541070871c7a8d9c
2000821351
v4609719YfsCFpf

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
I'm not looking for other ideas, the main thing here is that I have about
30-100 regex's in the database and the script fetches them and applies them
to the string. I can't build again the engine and I'm not going to do that.
I'm trying to solve my problem ;) If you have any ideas regarding my issue
and not going in another way this would be very appreciated.

Thank you again for trying to help.

On Fri, Mar 6, 2009 at 11:40 PM, Jim Lucas  wrote:

> Nitsan Bin-Nun wrote:
> > Hi lista,
> >
> > I have been trying to figure this out for the last couple of hours but
> I'm
> > lack of luck.
> > Take a look at these regex's, the string that was inputed into the
> > preg_replace (using Uis modificators) and the results:
> > (the lists have correspondence to each other)
> >
> > ORIGINAL STRING
> > 
> >
> > http://www.zshare.net/video/541070871c7a8d9c
> > http://www.guba.com/watch/2000821351
> > http://www.veoh.com/videos/v4609719YfsCFpf
> >
> >
> > REGEX USED (with Uis modificators)
> > 
> > http:\/\/(www\.|)zshare\.net\/video\/([^\/]+)   $3
> > http:\/\/(www\.|)guba\.com\/watch\/([0-9]+)  $3
> > http:\/\/(www\.|)veoh\.com\/videos\/([^\/]+)
> >
> > THE RETURNED STRING
> > 
> > 41070871c7a8d9c
> > 000821351
> > 4609719YfsCFpf
> >
> > If you will go through this carefully you will notice that the first
> > character of each matching group is being deleted.
> > The regex's and the replacements string are being fetched from the
> database
> > (mysql) and goes straight to the preg_replace function with the original
> > string.
> >
> > I have no idea why this happens.
> > I'm looking forward for your opinions and suggestions.
> >
> > Regards,
> > Nitsan
> >
>
> In my opinion...
>
> http://us3.php.net/parse_url   is your friend here...
>
> 
> $urls[] = 'http://www.zshare.net/video/541070871c7a8d9c';
> $urls[] = 'http://www.guba.com/watch/2000821351';
> $urls[] = 'http://www.veoh.com/videos/v4609719YfsCFpf';
>
> $url_paths = array();
>
> foreach ( $urls AS $id => $url ) {
>$url_paths[$id] = parse_url($url, PHP_URL_PATH);
> }
>
> print_r($url_paths);
>
> foreach ( $url_paths AS $paths ) {
>list( , ,$value) = explode('/', $paths, 3);
>echo $value;
> }
>
> ?>
>
> The above outputs the following:
>
>
>
> --
> Jim Lucas
>
>   "Some men are born to greatness, some achieve greatness,
>   and some have greatness thrust upon them."
>
> Twelfth Night, Act II, Scene V
>by William Shakespeare
>


Re: [PHP] insert array values

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 3:00 PM, PJ  wrote:
> I've been racking my little peanut-brain as well as big Google with
> little hope...
> I can retrieve the array from the multiple select dropdown box but I
> can't quite manage to insert the data which is just id numbers for a table.
> I've tried some while stuff but doesn't work. I know I don't have the
> right syntax on anything at this point. Here's an effort that doesn' work.
> Dont know if I should be using $categoriesIN[] type of stuff...
> but my tries were from web illustrations...
> the outcommented line returns the values of the array... but how to pass
> them to the query?
>
> foreach ($categoriesIN as $category) {
>    //"$category";
> $sql = "INSERT INTO book_categories ( book_id, category )
>    VALUES( book.id WHERE title = $titleIN, $category )";
>        $result = mysql_query($query, $db);;
>    }

Phil, you don't want to use an INSERT if you're just updating an
existing row. You can't do an INSERT and use the current row's values
(book.id/book_id/whatever) in your insert, since there IS no current
row. I'm assuming what you're trying to do is add a record to an
associative table that links Categories to Books, but only if that
Book title matches your $title string.

Try this:

foreach($categoriesIN as $category)
$sql = "update book_categories set category = '$category' where
book_id in (select id from book where title = '$titleIN')";

If that's not what you're going for, and you just wanted to update
something's category, try this:

foreach($categoriesIN as $category)
$sql = "update book_categories set category = '$category' where
book_id = '$somevalue'";

Perhaps it would help us help you if you would explain what it is
you're trying to accomplish with this query?


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun  wrote:
> I'm not looking for other ideas, the main thing here is that I have about
> 30-100 regex's in the database and the script fetches them and applies them
> to the string. I can't build again the engine and I'm not going to do that.
> I'm trying to solve my problem ;) If you have any ideas regarding my issue
> and not going in another way this would be very appreciated.

Nitsan,

I think it's because you're referencing the capture group with index
instead of index 2. Also, I don't understand why you have the pipe
("|") character in your regex string... is that part of your engine?

This code:

$orig = 'http://www.zshare.net/video/541070871c7a8d9c';
$matches = array();
preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig, $matches);
echo $matches[2];

Grabs the correct match:

541070871c7a8d9c

The regex pattern works with the pipe char, but it is unnecessary and
may lead to some strange behavior.

Hope this helps,


--
// Todd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 3:53 PM, haliphax  wrote:
> On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun  wrote:
>> I'm not looking for other ideas, the main thing here is that I have about
>> 30-100 regex's in the database and the script fetches them and applies them
>> to the string. I can't build again the engine and I'm not going to do that.
>> I'm trying to solve my problem ;) If you have any ideas regarding my issue
>> and not going in another way this would be very appreciated.
>
> Nitsan,
>
> I think it's because you're referencing the capture group with index
> instead of index 2. Also, I don't understand why you have the pipe
> ("|") character in your regex string... is that part of your engine?

*cough*... I meant to say "index 3 instead of index 2".

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread PJ
Bastien Koert wrote:
> On Fri, Mar 6, 2009 at 4:00 PM, PJ  wrote:
>
>   
>> I've been racking my little peanut-brain as well as big Google with
>> little hope...
>> I can retrieve the array from the multiple select dropdown box but I
>> can't quite manage to insert the data which is just id numbers for a table.
>> I've tried some while stuff but doesn't work. I know I don't have the
>> right syntax on anything at this point. Here's an effort that doesn' work.
>> Dont know if I should be using $categoriesIN[] type of stuff...
>> but my tries were from web illustrations...
>> the outcommented line returns the values of the array... but how to pass
>> them to the query?
>>
>> foreach ($categoriesIN as $category) {
>>//"$category";
>> $sql = "INSERT INTO book_categories ( book_id, category )
>>VALUES( book.id WHERE title = $titleIN, $category )";
>>$result = mysql_query($query, $db);;
>>}
>> TIA
>>
>> --
>> unheralded genius: "A clean desk is the sign of a dull mind. "
>> -
>> Phil Jourdan --- p...@ptahhotep.com
>>   http://www.ptahhotep.com
>>   http://www.chiccantine.com/andypantry.php
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>> 
> As its an array, you could join the data with an IMPLODE into a string, but
> does that meet your needs? The other option is to create a sub-table for
> this element and insert each item thru a loop individually.
>
>   
The returned array holds numbers like 1 or 2 or 3 or whatever up to60+
I need to enter the id of book.id into book_categories.book_id and the
values from the array into book_categories.categories_id.
book_categories is an intersecting table with foreign keys relating book
to categories.
The entries need to show the categories that are related to the book.
So, if the book.id = 1 and the categories id are 2, 4 and 5 I have to see
book_id  |   categories_id
--
   1 |   2|
   1 |   4|
   1 |   5|
__

At least, I think so... :-)
>From what I understood from all the posts and tutorials and manuals was
that my code should work unless I have made some syntax boo-boo.
I would think that this should be a series of inserts with only the
$category or $categoryIN changing...

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Thank you Todd, I also want to capture when I don't have the www in the
beginning of the URL.
For instance, try to execute your code with
$orig = 
'http://zshare.net/video/541070871c7a8d9c
';

That's why I used (www\.|), but I'm not a regex expert and I'm sure there a
way better solutions to this problem.

On Fri, Mar 6, 2009 at 11:53 PM, haliphax  wrote:

> On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun 
> wrote:
> > I'm not looking for other ideas, the main thing here is that I have about
> > 30-100 regex's in the database and the script fetches them and applies
> them
> > to the string. I can't build again the engine and I'm not going to do
> that.
> > I'm trying to solve my problem ;) If you have any ideas regarding my
> issue
> > and not going in another way this would be very appreciated.
>
> Nitsan,
>
> I think it's because you're referencing the capture group with index
> instead of index 2. Also, I don't understand why you have the pipe
> ("|") character in your regex string... is that part of your engine?
>
> This code:
>
> $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
> $matches = array();
> preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig, $matches);
> echo $matches[2];
>
> Grabs the correct match:
>
> 541070871c7a8d9c
>
> The regex pattern works with the pipe char, but it is unnecessary and
> may lead to some strange behavior.
>
> Hope this helps,
>
>
> --
> // Todd
>


Re: [PHP] insert array values

2009-03-06 Thread PJ
haliphax wrote:
> On Fri, Mar 6, 2009 at 3:00 PM, PJ  wrote:
>> I've been racking my little peanut-brain as well as big Google with
>> little hope...
>> I can retrieve the array from the multiple select dropdown box but I
>> can't quite manage to insert the data which is just id numbers for a
>> table.
>> I've tried some while stuff but doesn't work. I know I don't have the
>> right syntax on anything at this point. Here's an effort that doesn'
>> work.
>> Dont know if I should be using $categoriesIN[] type of stuff...
>> but my tries were from web illustrations...
>> the outcommented line returns the values of the array... but how to pass
>> them to the query?
>>
>> foreach ($categoriesIN as $category) {
>> Â  Â //"$category";
>> $sql = "INSERT INTO book_categories ( book_id, category )
>> Â  Â VALUES( book.id WHERE title = $titleIN, $category )";
>> Â  Â  Â  Â $result = mysql_query($query, $db);;
>> Â  Â }
>
> Phil, you don't want to use an INSERT if you're just updating an
> existing row. You can't do an INSERT and use the current row's values
> (book.id/book_id/whatever) in your insert, since there IS no current
> row. I'm assuming what you're trying to do is add a record to an
> associative table that links Categories to Books, but only if that
> Book title matches your $title string.
>
> Try this:
>
> foreach($categoriesIN as $category)
> $sql = "update book_categories set category = '$category' where
> book_id in (select id from book where title = '$titleIN')";
>
> If that's not what you're going for, and you just wanted to update
> something's category, try this:
>
> foreach($categoriesIN as $category)
> $sql = "update book_categories set category = '$category' where
> book_id = '$somevalue'";
>
> Perhaps it would help us help you if you would explain what it is
> you're trying to accomplish with this query?
Hmmm, maybe I'm chasing my own tail...
following the trail of execution is tough... :'(
I'm trying to enter a new book into the database and that means I have
to enter the info for the relational tables as well.
I think I stumbled here a bit as what I need is the id that is inserted
in the db before inserting this category stuff.
As I look at the code, it looks like i have to find the
"last-entered-id" for the book that is being entered.

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 4:01 PM, Nitsan Bin-Nun  wrote:
> On Fri, Mar 6, 2009 at 11:53 PM, haliphax  wrote:
>>
>> On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun 
>> wrote:
>> > I'm not looking for other ideas, the main thing here is that I have
>> > about
>> > 30-100 regex's in the database and the script fetches them and applies
>> > them
>> > to the string. I can't build again the engine and I'm not going to do
>> > that.
>> > I'm trying to solve my problem ;) If you have any ideas regarding my
>> > issue
>> > and not going in another way this would be very appreciated.
>>
>> Nitsan,
>>
>> I think it's because you're referencing the capture group with index
>> instead of index 2. Also, I don't understand why you have the pipe
>> ("|") character in your regex string... is that part of your engine?
>>
>> This code:
>>
>> $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
>> $matches = array();
>> preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig, $matches);
>> echo $matches[2];
>>
>> Grabs the correct match:
>>
>> 541070871c7a8d9c
>>
>> The regex pattern works with the pipe char, but it is unnecessary and
>> may lead to some strange behavior.
>
> Thank you Todd, I also want to capture when I don't have the www in the
> beginning of the URL.
> For instance, try to execute your code with
> $orig = 'http://zshare.net/video/541070871c7a8d9c';
>
> That's why I used (www\.|), but I'm not a regex expert and I'm sure there a
> way better solutions to this problem.

http://www.regular-expressions.info is your best friend. Spend an
afternoon playing around on it... that's really the only advantage I
have over someone who hasn't.

Anyway, you can make that entire group optional with the ? character like so:

#http://(www\.)?zshare\.net/video/([^/]+)#

And if you don't want it to be captured, making the URL suffix index 1
instead of index 2, do this:

#http://(?:www\.)?zshare\.net/video/([^/]+)#

Any group that begins with "?:" will not be captured in a match index. To recap:

$pattern = '#http://(?:www\.)?zshare\.net/video/([^/]+)#';
$orig = 'http://zshare.net/video/541070871c7a8d9c';
$matches = array();
preg_match($pattern, $orig, $matches);
echo $matches[1] . "\n";
$orig = 'http://www.zshare.net/video/541070871c7a8d9c';
preg_match($pattern, $orig, $matches);
echo $matches[1] . "\n";

Produces this output:

541070871c7a8d9c
541070871c7a8d9c

Hope this helps,


-- 
// Todd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Unexplained Issue Using Regex

2009-03-06 Thread Nitsan Bin-Nun
Got it, thank you Todd.

I usually tend to use string based functions instead of regex, but sometimes
regex is a better option.

On Sat, Mar 7, 2009 at 12:16 AM, haliphax  wrote:

> On Fri, Mar 6, 2009 at 4:01 PM, Nitsan Bin-Nun 
> wrote:
> > On Fri, Mar 6, 2009 at 11:53 PM, haliphax  wrote:
> >>
> >> On Fri, Mar 6, 2009 at 3:44 PM, Nitsan Bin-Nun 
> >> wrote:
> >> > I'm not looking for other ideas, the main thing here is that I have
> >> > about
> >> > 30-100 regex's in the database and the script fetches them and applies
> >> > them
> >> > to the string. I can't build again the engine and I'm not going to do
> >> > that.
> >> > I'm trying to solve my problem ;) If you have any ideas regarding my
> >> > issue
> >> > and not going in another way this would be very appreciated.
> >>
> >> Nitsan,
> >>
> >> I think it's because you're referencing the capture group with index
> >> instead of index 2. Also, I don't understand why you have the pipe
> >> ("|") character in your regex string... is that part of your engine?
> >>
> >> This code:
> >>
> >> $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
> >> $matches = array();
> >> preg_match('#http://(www\.)zshare\.net/video/([^/]+)#', $orig,
> $matches);
> >> echo $matches[2];
> >>
> >> Grabs the correct match:
> >>
> >> 541070871c7a8d9c
> >>
> >> The regex pattern works with the pipe char, but it is unnecessary and
> >> may lead to some strange behavior.
> >
> > Thank you Todd, I also want to capture when I don't have the www in the
> > beginning of the URL.
> > For instance, try to execute your code with
> > $orig = 'http://zshare.net/video/541070871c7a8d9c';
> >
> > That's why I used (www\.|), but I'm not a regex expert and I'm sure there
> a
> > way better solutions to this problem.
>
> http://www.regular-expressions.info is your best friend. Spend an
> afternoon playing around on it... that's really the only advantage I
> have over someone who hasn't.
>
> Anyway, you can make that entire group optional with the ? character like
> so:
>
> #http://(www\.)?zshare\.net/video/([^/]+)#
>
> And if you don't want it to be captured, making the URL suffix index 1
> instead of index 2, do this:
>
> #http://(?:www\.)?zshare\.net/video/([^/]+)#
>
> Any group that begins with "?:" will not be captured in a match index. To
> recap:
>
> $pattern = '#http://(?:www\.)?zshare\.net/video/([^/]+)#';
> $orig = 'http://zshare.net/video/541070871c7a8d9c';
> $matches = array();
> preg_match($pattern, $orig, $matches);
> echo $matches[1] . "\n";
> $orig = 'http://www.zshare.net/video/541070871c7a8d9c';
> preg_match($pattern, $orig, $matches);
> echo $matches[1] . "\n";
>
> Produces this output:
>
> 541070871c7a8d9c
> 541070871c7a8d9c
>
> Hope this helps,
>
>
> --
> // Todd
>


[PHP] Re: Sending out large amounts of email

2009-03-06 Thread Brian Hansen
Thank you all for some great answer and insights.

Special thanks to Chris, Nathan and Manuel for very valuable pointers and
sharing of information and experience.

For those interested in the subject..

We have our own servers, and since we want to be in control of the situation
ourselves we are not going to out-source the task.

I have chosen to go with a setup using PHPMailer on a mailserver running
Postfix and PostgreSQL. I have come to the conclusion that running PHPMailer
through the Sendmail binary (Postfix wrapper in this case) is the fastest
method.

Using Postfix this way doesn't use a queue, so what I do is that the script
saves the body and headers in a database table. In another table alle the
different email addresses is saved using a loop. Currently I am looking into
a better approach, but I haven't had the time yet. But I was thinking of
something like having a field for marking customers as receivers.

A cronjob is then run each two minuts (or something like that) calling a
small PHP script that uses PHPMailer to send out about 1000-3000 mails at a
time (it takes about 1 sec. and only about 24% of CPU power in our case
during that second). It loops through the customer emails.

Thanks to Chris I have looked into the subject of SPF, and I have created
the nesecary SPF TXT records for the relevant domain (thanks a thousand
Chris, I had completely forgotten about SPF).

I have run a couple of tests and so far every mailboks I have testet (Gmail,
Hotmail, different ISP's etc) have received the mail directly in the inbox,
except for Hotmail (typical) that puts the mail in the Junk box, but atleast
it gets through!

I have found this solution rather simple and very easy to maintain.

Best regards.

2009/3/6 Brian Hansen 

> Hi.
>
> Our company is merging with another company and newsletter now needs to go
> out to more than 100.000 people. Before it was only a couple of thousands.
>
> I have developed a mail queue using a database and a cronjob, but I am not
> in doubt as to what particular solution I need to implement.
>
> I have been running some tests with PHP mail() function, PHPMailer and
> PEAR:Mail using 6000 mails at once.
>
> Here's a sumarry of some of the results:
>
> PHP mail() send out 6000 mails in 1.75 seconds.
> PHPMailer using PHP mail() send out 6000 mails in 1.87 seconds.
> PHPMailer using SMTP send out 6000 mails in 12 seconds (Error without
> succes).
> PEAR:Mail using PHP mail() send out 6000 mails in > 20 seconds (Apache
> reached 100% during this time).
>
> Running several test on PHPMailer using SMTP failed completely with more
> than 1000 mails.
>
> Everywhere on the net I read that sending out mail using PHP mail() is slow
> and it is a bad idea and that using some mail class with SMTP directly would
> be much better. I have tested the run my tests with Postfix as the SMTP.
>
> I have gotten the best results using PHP mail(). When the volume is belove
> 6000 PHP mail() is by far the fastest.
>
> Would someone mind sharing experience and perhaps shedding some light on
> this issue?
>
> What is the best solution in real life dealing with huge amounts of mail?
> PHP mail() vs. some class using SMTP or binary sendmail (or wrapper)?
>
> All insights would be appriciated.
>
> Best regards.
>
> Brian
>
>
>


Re: [PHP] insert array values

2009-03-06 Thread haliphax
On Fri, Mar 6, 2009 at 4:07 PM, PJ  wrote:
> haliphax wrote:
>> On Fri, Mar 6, 2009 at 3:00 PM, PJ  wrote:
>>> I've been racking my little peanut-brain as well as big Google with
>>> little hope...
>>> I can retrieve the array from the multiple select dropdown box but I
>>> can't quite manage to insert the data which is just id numbers for a
>>> table.
>>> I've tried some while stuff but doesn't work. I know I don't have the
>>> right syntax on anything at this point. Here's an effort that doesn'
>>> work.
>>> Dont know if I should be using $categoriesIN[] type of stuff...
>>> but my tries were from web illustrations...
>>> the outcommented line returns the values of the array... but how to pass
>>> them to the query?
>>>
>>> foreach ($categoriesIN as $category) {
>>> Â  Â //"$category";
>>> $sql = "INSERT INTO book_categories ( book_id, category )
>>> Â  Â VALUES( book.id WHERE title = $titleIN, $category )";
>>> Â  Â  Â  Â $result = mysql_query($query, $db);;
>>> Â  Â }
>>
>> Phil, you don't want to use an INSERT if you're just updating an
>> existing row. You can't do an INSERT and use the current row's values
>> (book.id/book_id/whatever) in your insert, since there IS no current
>> row. I'm assuming what you're trying to do is add a record to an
>> associative table that links Categories to Books, but only if that
>> Book title matches your $title string.
>>
>> Try this:
>>
>> foreach($categoriesIN as $category)
>> $sql = "update book_categories set category = '$category' where
>> book_id in (select id from book where title = '$titleIN')";
>>
>> If that's not what you're going for, and you just wanted to update
>> something's category, try this:
>>
>> foreach($categoriesIN as $category)
>> $sql = "update book_categories set category = '$category' where
>> book_id = '$somevalue'";
>>
>> Perhaps it would help us help you if you would explain what it is
>> you're trying to accomplish with this query?
> Hmmm, maybe I'm chasing my own tail...
> following the trail of execution is tough... :'(
> I'm trying to enter a new book into the database and that means I have
> to enter the info for the relational tables as well.
> I think I stumbled here a bit as what I need is the id that is inserted
> in the db before inserting this category stuff.
> As I look at the code, it looks like i have to find the
> "last-entered-id" for the book that is being entered.

Well, there are two ways you can do that with PHP/MySQL. First, you
can do it on the DB server. Second, you can do it in PHP after your
insert query has been performed.

MySQL:
SELECT LAST_INSERT_ID();

PHP:
mysql_query("insert into tablename(foo, bar) values('foo', 'bar');", $db);
echo mysql_insert_id();

If you're just trying to tie a book to existing categories, I would
insert the book and then separately insert the records in the
associative table (book_categories).

Pseudocode:
insert book into book table
grab last inserted id with mysql_insert_id()
for each category book is a part of
{
  insert book (via last inserted id) and category IDs into book_categories
}

If you're trying to insert a book and a category and then link them
together, I would do this:

Pseudocode:
insert book into book table
grab last inserted book id with mysql_insert_id()
insert category into category table
grab last inserted category id with mysql_insert_id()
insert last book and last category IDs into book_categories

Hope this helps,


-- 
// Todd

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread PJ
haliphax wrote:
> On Fri, Mar 6, 2009 at 4:07 PM, PJ  wrote:
>> haliphax wrote:
>>> On Fri, Mar 6, 2009 at 3:00 PM, PJ  wrote:
 I've been racking my little peanut-brain as well as big Google with
 little hope...
 I can retrieve the array from the multiple select dropdown box but I
 can't quite manage to insert the data which is just id numbers for a
 table.
 I've tried some while stuff but doesn't work. I know I don't have the
 right syntax on anything at this point. Here's an effort that doesn'
 work.
 Dont know if I should be using $categoriesIN[] type of stuff...
 but my tries were from web illustrations...
 the outcommented line returns the values of the array... but how to
 pass
 them to the query?

 foreach ($categoriesIN as $category) {
 Â  Â //"$category";
 $sql = "INSERT INTO book_categories ( book_id, category )
 Â  Â VALUES( book.id WHERE title = $titleIN, $category )";
 Â  Â  Â  Â $result = mysql_query($query, $db);;
 Â  Â }
>>> Phil, you don't want to use an INSERT if you're just updating an
>>> existing row. You can't do an INSERT and use the current row's values
>>> (book.id/book_id/whatever) in your insert, since there IS no current
>>> row. I'm assuming what you're trying to do is add a record to an
>>> associative table that links Categories to Books, but only if that
>>> Book title matches your $title string.
>>>
>>> Try this:
>>>
>>> foreach($categoriesIN as $category)
>>> $sql = "update book_categories set category = '$category' where
>>> book_id in (select id from book where title = '$titleIN')";
>>>
>>> If that's not what you're going for, and you just wanted to update
>>> something's category, try this:
>>>
>>> foreach($categoriesIN as $category)
>>> $sql = "update book_categories set category = '$category' where
>>> book_id = '$somevalue'";
>>>
>>> Perhaps it would help us help you if you would explain what it is
>>> you're trying to accomplish with this query?
>> Hmmm, maybe I'm chasing my own tail...
>> following the trail of execution is tough... :'(
>> I'm trying to enter a new book into the database and that means I have
>> to enter the info for the relational tables as well.
>> I think I stumbled here a bit as what I need is the id that is inserted
>> in the db before inserting this category stuff.
>> As I look at the code, it looks like i have to find the
>> "last-entered-id" for the book that is being entered.
>
> Well, there are two ways you can do that with PHP/MySQL. First, you
> can do it on the DB server. Second, you can do it in PHP after your
> insert query has been performed.
>
> MySQL:
> SELECT LAST_INSERT_ID();
>
> PHP:
> mysql_query("insert into tablename(foo, bar) values('foo', 'bar');", $db);
> echo mysql_insert_id();
>
> If you're just trying to tie a book to existing categories, I would
> insert the book and then separately insert the records in the
> associative table (book_categories).
>
> Pseudocode:
> insert book into book table
> grab last inserted id with mysql_insert_id()
> for each category book is a part of
> {
> insert book (via last inserted id) and category IDs into book_categories
> }
>
> If you're trying to insert a book and a category and then link them
> together, I would do this:
>
> Pseudocode:
> insert book into book table
> grab last inserted book id with mysql_insert_id()
> insert category into category table
> grab last inserted category id with mysql_insert_id()
> insert last book and last category IDs into book_categories
>
> Hope this helps,
Well, I did this but it don't woik...
foreach($categoriesIN as $category)
/* $sql = "update book_categories set category = '$category' where
book_id = '$autoid'";*/
$sql = "INSERT INTO book_categories ( book_id, categories_id )
VALUES ( '$autoid', '$category' )";
$result = mysql_query($sql, $db);
neither one; the INSER enter only the last value but misses the other 3
that were there; there should be like 4 book_ids with 1 and the
correspongind catgories_id should contain 1,2, 4,5 respectively...

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread PJ
haliphax wrote:
> On Fri, Mar 6, 2009 at 4:07 PM, PJ  wrote:
>   
>> haliphax wrote:
>> 
>>> On Fri, Mar 6, 2009 at 3:00 PM, PJ  wrote:
>>>   
 I've been racking my little peanut-brain as well as big Google with
 little hope...
 I can retrieve the array from the multiple select dropdown box but I
 can't quite manage to insert the data which is just id numbers for a
 table.
 I've tried some while stuff but doesn't work. I know I don't have the
 right syntax on anything at this point. Here's an effort that doesn'
 work.
 Dont know if I should be using $categoriesIN[] type of stuff...
 but my tries were from web illustrations...
 the outcommented line returns the values of the array... but how to pass
 them to the query?

 foreach ($categoriesIN as $category) {
 Â  Â //"$category";
 $sql = "INSERT INTO book_categories ( book_id, category )
 Â  Â VALUES( book.id WHERE title = $titleIN, $category )";
 Â  Â  Â  Â $result = mysql_query($query, $db);;
 Â  Â }
 
>>> Phil, you don't want to use an INSERT if you're just updating an
>>> existing row. You can't do an INSERT and use the current row's values
>>> (book.id/book_id/whatever) in your insert, since there IS no current
>>> row. I'm assuming what you're trying to do is add a record to an
>>> associative table that links Categories to Books, but only if that
>>> Book title matches your $title string.
>>>
>>> Try this:
>>>
>>> foreach($categoriesIN as $category)
>>> $sql = "update book_categories set category = '$category' where
>>> book_id in (select id from book where title = '$titleIN')";
>>>
>>> If that's not what you're going for, and you just wanted to update
>>> something's category, try this:
>>>
>>> foreach($categoriesIN as $category)
>>> $sql = "update book_categories set category = '$category' where
>>> book_id = '$somevalue'";
>>>
>>> Perhaps it would help us help you if you would explain what it is
>>> you're trying to accomplish with this query?
>>>   
>> Hmmm, maybe I'm chasing my own tail...
>> following the trail of execution is tough... :'(
>> I'm trying to enter a new book into the database and that means I have
>> to enter the info for the relational tables as well.
>> I think I stumbled here a bit as what I need is the id that is inserted
>> in the db before inserting this category stuff.
>> As I look at the code, it looks like i have to find the
>> "last-entered-id" for the book that is being entered.
>> 
>
> Well, there are two ways you can do that with PHP/MySQL. First, you
> can do it on the DB server. Second, you can do it in PHP after your
> insert query has been performed.
>
> MySQL:
> SELECT LAST_INSERT_ID();
>
> PHP:
> mysql_query("insert into tablename(foo, bar) values('foo', 'bar');", $db);
> echo mysql_insert_id();
>
> If you're just trying to tie a book to existing categories, I would
> insert the book and then separately insert the records in the
> associative table (book_categories).
>
> Pseudocode:
> insert book into book table
> grab last inserted id with mysql_insert_id()
> for each category book is a part of
> {
>   insert book (via last inserted id) and category IDs into book_categories
> }
>
> If you're trying to insert a book and a category and then link them
> together, I would do this:
>
> Pseudocode:
> insert book into book table
> grab last inserted book id with mysql_insert_id()
> insert category into category table
> grab last inserted category id with mysql_insert_id()
> insert last book and last category IDs into book_categories
>
> Hope this helps,
>   
The problem is that every book may have several categories and I'm just
not getting them inserted, updated or whatever...
I understand the psuedocode (which for me is the logical thread of the
script) I just don't got the gits. ;-)

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread PJ
I've done some rethingking and this may be the direction to go:

What I need to wind up with is something like this:

$sql = "INSERT INTO book_categories ( book_id, category )
VALUES( '$autoID', '$categoriesID[0]' ),
( '$autoID', '$categoriesID[1]' ),   
( '$autoID', '$categoriesID[2]' ),
( '$autoID', '$categoriesID[3]' )
( '$autoID', '$categoriesID[4]' )";

Does it make sense?
How do I pass the values to the query?



-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread 9el
On Sat, Mar 7, 2009 at 5:37 AM, PJ  wrote:

> I've done some rethingking and this may be the direction to go:
>
> What I need to wind up with is something like this:
>
> $sql = "INSERT INTO book_categories ( book_id, category )
> VALUES( '$autoID', '$categoriesID[0]' ),
>( '$autoID', '$categoriesID[1]' ),
>( '$autoID', '$categoriesID[2]' ),
>( '$autoID', '$categoriesID[3]' )
>( '$autoID', '$categoriesID[4]' )";
>
> Does it make sense?
> How do I pass the values to the query?
>
>
>
> You can run a php loop inside the insert  clause.
But if its already existing record then it woud be UPDATE clause.


[PHP] PHP and named groups in regex/PCRE

2009-03-06 Thread Daevid Vincent
A friend was showing off his regex-fu and the virtues of "named groups"
and how great Python is, knowing that PHP had to be equally as good
(since it uses the same PCRE libraries), we whipped up this little test.
So now us PHP folks can enjoy the same benefit! :-)

vince...@dev1:~$ cat ./named_groups_test.php 
http://us.php.net/manual/en/function.preg-match.php
//http://www.regular-expressions.info/named.html

preg_match("/(?Pabc)(.*)(?Pxyz)/",
   'abcdefghijklmnopqrstuvwxyz',
   $matches);
print_r($matches);
?>

vince...@dev1:~$ php ./named_groups_test.php 
Array
(
[0] => abcdefghijklmnopqrstuvwxyz
[foo] => abc
[1] => abc
[2] => defghijklmnopqrstuvw
[bar] => xyz
[3] => xyz
)



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Clancy
On Fri, 6 Mar 2009 08:53:44 -0500, danbr...@php.net (Daniel Brown) wrote:

>On Fri, Mar 6, 2009 at 00:12, Clancy  wrote:
>>
>> Don't take me too seriously on this. But it riles me that the same peoplewho 
>> threw out the
>> GOTO as being too dangerous could then introduce the break statement which, 
>> as I said,
>> it's like a GOTO without a target. As a long-time assembly programmer, I 
>> found the
>> judicious use of GOTO's made for far clearer code than the mess of nested 
>> braces I am
>> forced to use in PHP.
>
>Then you'll be happy with the advent of PHP6:
>
>http://php.net/goto

Great news! .. Now ALL I have to do is to persuade my host to update from 
4.3.9. (or
maybe switch!)


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP and named groups in regex/PCRE

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 19:12, Daevid Vincent  wrote:
> A friend was showing off his regex-fu and the virtues of "named groups"
> and how great Python is, knowing that PHP had to be equally as good
> (since it uses the same PCRE libraries), we whipped up this little test.
> So now us PHP folks can enjoy the same benefit! :-)

Appending to Daevid's post, a snippet from the note he posted
about this a little bit ago (it will appear on the manual entry soon):

Note that you actually get the named group as well as the
numerical key value too, so if you do use them, and you're counting
array elements, be aware that your array might be bigger than you
initially expect it to be.

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Daniel Brown
On Fri, Mar 6, 2009 at 19:29, Clancy  wrote:
>
> Great news! .. Now ALL I have to do is to persuade my host to update from 
> 4.3.9. (or
> maybe switch!)

If your host is only using PHP4, you probably should switch
because who knows what else they've chosen not to upgrade.  Check out
the forums at http://www.webhostingtalk.com/ for info on that.

Just keep in mind that neither PHP 5.3 (where GOTO actually comes
into play --- I typed PHP6 without thinking) nor PHP6 are yet
officially released, and aren't likely to be in production anywhere
yet.

-- 

daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Website on a USB key?

2009-03-06 Thread Clancy
On Fri, 6 Mar 2009 05:51:36 -0800 (PST), seanodot...@yahoo.com (Sean O) wrote:

>
>Another good website-on-a-stick software is... well, WOS (now called MoWeS --
>Modular Webserver System).
>http://www.chsoftware.net/en/useware/mowes/mowes.htm
>
>The nice thing about this software is the ability to download "packages" of
>just about any major server-based software -- Drupal, Mambo, Joomla, Moodle,
>SugarCRM, WordPress, etc.
>http://www.chsoftware.net/en/useware/mowesmixer/mowesmixer.htm?step=2
>
>And, of course, run it all from your USB Drive.
>
Thanks,

That sounds like what i was thinking of.  The only reason for doing such a 
thing is so you
can poke the key into someone elses PC & run a demo without changing anything 
on their
machine.

Not a high priority though; I already have my websites on my laptop.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread PJ
9el wrote:
>
> On Sat, Mar 7, 2009 at 5:37 AM, PJ  > wrote:
>
> I've done some rethingking and this may be the direction to go:
>
> What I need to wind up with is something like this:
>
> $sql = "INSERT INTO book_categories ( book_id, category )
>VALUES( '$autoID', '$categoriesID[0]' ),
>( '$autoID', '$categoriesID[1]' ),
>( '$autoID', '$categoriesID[2]' ),
>( '$autoID', '$categoriesID[3]' )
>( '$autoID', '$categoriesID[4]' )";
>
> Does it make sense?
> How do I pass the values to the query?
>
>
>
> You can run a php loop inside the insert  clause.
> But if its already existing record then it woud be UPDATE clause.
>
Could I have a small hint as to how to do that. I'll check the manual
and search G in the meantime.  Right now, it's Friday night and I'm
about to get whammied by the wife... ;-)  have a good night & let's
hope for a brighter tomorrow, tomorrow, tomorro

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] insert array values

2009-03-06 Thread Jim Lucas
PJ wrote:
> 9el wrote:
>> On Sat, Mar 7, 2009 at 5:37 AM, PJ > > wrote:
>>
>> I've done some rethingking and this may be the direction to go:
>>
>> What I need to wind up with is something like this:
>>
>> $sql = "INSERT INTO book_categories ( book_id, category )
>>VALUES( '$autoID', '$categoriesID[0]' ),
>>( '$autoID', '$categoriesID[1]' ),
>>( '$autoID', '$categoriesID[2]' ),
>>( '$autoID', '$categoriesID[3]' )
>>( '$autoID', '$categoriesID[4]' )";
>>
>> Does it make sense?
>> How do I pass the values to the query?
>>
>>
>>
>> You can run a php loop inside the insert  clause.
>> But if its already existing record then it woud be UPDATE clause.
>>
> Could I have a small hint as to how to do that. I'll check the manual
> and search G in the meantime.  Right now, it's Friday night and I'm
> about to get whammied by the wife... ;-)  have a good night & let's
> hope for a brighter tomorrow, tomorrow, tomorro
> 


To do something like what you are describing above, you would do the following:

 $id ) {

# Build VALUES entry, plus run $id through escape 
function for sanity
$values[] = "( {$last_id}, 
".mysql_real_escape_string($id)." )";
}

# Join the VALUES entries just created and separate them with a 
comma
$sql = "INSERT INTO book_categories ( book_id, category ) 
VALUES " . join(', ', $values);

# Execute book 2 categories SQL entry
if ( ( $results = mysql_query($sql, $dblink) ) === false ) {

# If it fails, show me why
echo 'Book to category entry failed: 
'.mysql_error($dblink);
}
}
} else {
# Show why my book SQL entry failed
echo "Book insert failed: ".mysql_error($dblink);
}

?>

That is about as best as can be explained.

BTW - I took away the quotes around your values in your second insert 
statement.  They are numbers and numbers should not have quotes around them.

Hopefully this works, or guides you in the direction of the answer you seek.

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP and named groups in regex/PCRE

2009-03-06 Thread Jim Lucas
Daevid Vincent wrote:
> A friend was showing off his regex-fu and the virtues of "named groups"
> and how great Python is, knowing that PHP had to be equally as good
> (since it uses the same PCRE libraries), we whipped up this little test.
> So now us PHP folks can enjoy the same benefit! :-)
> 
> vince...@dev1:~$ cat ./named_groups_test.php 
>  //http://us.php.net/manual/en/function.preg-match.php
> //http://www.regular-expressions.info/named.html
> 
> preg_match("/(?Pabc)(.*)(?Pxyz)/",
>'abcdefghijklmnopqrstuvwxyz',
>$matches);
> print_r($matches);
> ?>
> 
> vince...@dev1:~$ php ./named_groups_test.php 
> Array
> (
> [0] => abcdefghijklmnopqrstuvwxyz
> [foo] => abc
> [1] => abc
> [2] => defghijklmnopqrstuvw
> [bar] => xyz
> [3] => xyz
> )
> 
> 

This needs to be directed to whomever it was about six months ago that was 
asking about this.

They were trying to figure out how to do this, but I believe they were told 
that it could not be done.

Nice example!

-- 
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Clancy
On Fri, 6 Mar 2009 08:58:17 -0600, halip...@gmail.com (haliphax) wrote:

>>> >> >    I wholeheartedly concur.  The first programming language I taught
>>> >> > myself was BASIC about 23 years ago.  We may never see the inclusion
>>> >> > of GOSUB in PHP, but GOTO is certainly worthwhile.
>>> >> >
>>> >> >
>>> >> >    Side note: I wrote a BASIC interpreter in PHP about two weeks ago.
>>> >> >  Talk about fond memories.
>>> >>
>>> >> QuickBasic (actually QBasic, and then later QuickBasic when my mom
>>> >> shelled out the money for me to buy it) was my first language. I
>>> >> remember being completely flabbergasted when I found out they packaged
>>> >> an interpreter with DOS, and it had been under my nose the whole time.
>>> >> I think my first "finished" program was a D&D character generator.
>>> >> Basically, just colored and formatted text with the output of 6 or so
>>> >> random number generations.
>>> >>
>>> >> Meemorees... :D
>>> >
>>> > I did Basic on the TRS-80 and saved my programs to a big clunky audio
>>> > tape drive... 1... 2... 3... queue Tedd with rocks :)
>>>
>>> Oh, I'm not even trying to pretend like I'm half as old as some on
>>> this list. I still chew my own food, thank you very much. ;)
>>>
>>> (All in jest, of course... But some of you are pretty old. Ha!)
>>
>> I just turned 35... today... that's young by the standards of a 70 year
>> old >:)
>
>Well, I may not be decrepit just yet, but I am by no means a
>whippersnapper anymore. Looking at turning 27 this April. I'm sure
>some of the more geriatric people in the world still consider me a
>kid, but I can look at teenagers now and think, "What the hell are
>they doing that for?"

Yes, when I went to university the students were young adults. Now they are 
just kids!

When I started programming (in about 1967) I worked for the Commonwealth 
Scientific and
Industrial Research Organisation (CSIRO) in Australia. They had a little 
computer (a CDC
3200, costing $500,000 and with 32K of 24 bit words of core memory) in each 
capital city,
and a big computer (a CDC 3600, costing $2,000,000 and with 64K of 48 bit words 
of memory)
in Canberra. The little computers filled a large room, and had about 20 people 
operating
them. The big one filled a whole floor, and had about 50 people operating it.

I had to enter my programs on punch cards, and a courier would collect them 
twice a day
and take them to Clayton (another site about 10 miles away). Then he would 
bring back the
listings from the previous trip. After the morning run we had about 20 minutes 
to fix
obvious bugs before he collected the next batch, and we had overnight to fix 
the afternoon
run. When I got more ambitious, and started using the big computer, the cards 
were taken
to Clayton where they were transferred to mag tape, which was couriered to the 
airport and
flown to Canberra. The tapes were run overnight, and the listings written back 
to tapes,
which were flown back to Melbourne next morning, taken to Clayton, transferred 
to paper,
and brought back to our site. There was often fog in Canberra, which would 
close the
airport, so if we were lucky we would get three runs in a week. Any trivial 
change would
take a week to debug.

We were programming in Fortran, and the I/O support was extremely primitive. 
You had to
specify the format for every value you wished to read - eg F10.3 for a 10 digit 
floating
point number, with three digits after the decimal point, and you had to place 
the decimal
point in a specific column on the card. Despite all this I wrote a complex 
program for
analysing linear electronic circuits. It was effectively an interpreter for my 
own
high-level language.

I never understood how subroutines worked, as the concept of stacks had not been
developed, and you could jump into or out of loops and even subroutines with 
impunity. It
also had an 'assigned goto' instruction, which was perfect for writing 'write 
only'
software. My program was very simple. It consisted of a loop:

Assign initial pointers to switches 1 to 3;
Start: read a character;
if it's a number { GOTO switch_1; }
if it's a punctuation mark { GOTO switch_2; }
if it's anything else { GOTO switch_3; }
GOTO Start;

Initial_switch_1 procedure:
.
GOTO start;

Each time I found something interesting I would assign a new pointer to the 
appropriate
switch. This gave extremely compact code, enabling me to get my complicated 
program into
the ridiculously small memory, but I soon found that it was virtually 
impossible to debug,
as the settings of the switches at any moment depended on the whole previous 
history.

Presumably others made the same discovery, as the assigned goto never appeared 
on any
subsequent computer.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: if elseif elseif elseif....

2009-03-06 Thread Paul M Foster
On Sat, Mar 07, 2009 at 11:29:41AM +1100, Clancy wrote:

> On Fri, 6 Mar 2009 08:53:44 -0500, danbr...@php.net (Daniel Brown) wrote:
> 
> >On Fri, Mar 6, 2009 at 00:12, Clancy  wrote:



> >
> >Then you'll be happy with the advent of PHP6:
> >
> >http://php.net/goto
> 

Someone would add gotos to a language *on purpose*?!

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] verify another flavor

2009-03-06 Thread Paul M Foster
On Fri, Mar 06, 2009 at 10:49:12AM -0600, haliphax wrote:




> 
> I would go about it like this:
> 
> $sql1 = "select concat_ws(' ', first_name, last_name) as Author_Name
> from author where first_name = '$first_nameIN' and last_name =
> '$last_nameIN'";

If you already know the first_name and last_name and you're just
checking for their existence, then just query for some simple field like
"id". Then check for number of rows. If it's zero, it's not there.
There's no point in making MySQL return a value which you already know.

What is the fascination with using concat_ws()? Just say:

$name = $first_name . ' ' . $last_name;

or

$name = "$first_name $last_name";

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php