php-general Digest 30 Jun 2002 01:34:00 -0000 Issue 1435

Topics (messages 104484 through 104543):

Getting IP from behind proxies
        104484 by: JJ Harrison
        104486 by: Rasmus Lerdorf
        104543 by: JJ Harrison

Re: saving temporary image to database
        104485 by: Rasmus Lerdorf
        104492 by: andy

Re: Keeping "Secrets" in PHP Files
        104487 by: Jonathan Rosenberg

need to change $ char in string
        104488 by: Beverly Steiner
        104497 by: Uli B
        104498 by: Jason Wong
        104504 by: Beverly Steiner
        104505 by: Jason Wong
        104521 by: Paul Roberts
        104533 by: hugh danaher

ASP style "application-level" variables
        104489 by: Lee
        104490 by: John Holmes
        104491 by: John Holmes
        104502 by: Cal Evans

Populate Popup Menu from Database
        104493 by: Mike Tuller
        104495 by: Jason Wong
        104496 by: Cal Evans
        104500 by: Mike Tuller
        104501 by: Mike Tuller
        104503 by: Jason Wong
        104507 by: Chris Shiflett
        104509 by: Mike Tuller

Re: Constants
        104494 by: S.P. Telgenhof Oude Koehorst

Re: Gradients in PHP & GD
        104499 by: Bogdan Stancescu

Re: session.use_trans_sid
        104506 by: Dan Tappin

Sessions [Help]
        104508 by: Dan Tappin

change variable in file
        104510 by: Nookie

Limiting number of decimal places reported
        104511 by: John Wulff
        104512 by: Pushkar Pradhan
        104514 by: John Holmes

Javascript to PHP?
        104513 by: Jed Verity
        104515 by: John Holmes
        104516 by: Pushkar Pradhan
        104517 by: Jed Verity
        104519 by: Chris Shiflett
        104520 by: David Freeman
        104522 by: Mark Charette
        104523 by: Jed Verity
        104537 by: Bruce Karstedt
        104541 by: Mark

Generating RTF on the fly
        104518 by: Mario Bittencourt
        104524 by: Mirza Muharemagic
        104525 by: John Holmes
        104526 by: Gerhard Hoogterp
        104527 by: Manuel Lemos

Newbie Q: Fetching vs. Looping
        104528 by: Jed Verity
        104532 by: John Holmes
        104534 by: Chris Shiflett
        104536 by: Duncan Hill
        104540 by: Chris Shiflett
        104542 by: Duncan Hill

Dynamic List Boxes
        104529 by: Chase
        104530 by: Stuart Dallas
        104531 by: Chase

Usiing FOREACH to loop through Array
        104535 by: Brad Melendy
        104538 by: Steve Edberg
        104539 by: Steve Edberg

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
I want to check to see if people have voted yet for a poll.

How can I get the ip of a user from both behind a proxy and the proxies ip?

is this simple?

will i have trouble with firewalls etc?


--
JJ Harrison
[EMAIL PROTECTED]
www.tececo.com


--- End Message ---
--- Begin Message ---
You can only get it if the proxy provides you with this data.  Most don't,
so this is not a reliable approach.

-Rasmus

On Sat, 29 Jun 2002, JJ Harrison wrote:

> I want to check to see if people have voted yet for a poll.
>
> How can I get the ip of a user from both behind a proxy and the proxies ip?
>
> is this simple?
>
> will i have trouble with firewalls etc?
>
>
> --
> JJ Harrison
> [EMAIL PROTECTED]
> www.tececo.com
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
I want to check to see if people have voted yet for a poll.

How can I get the ip of a user from both behind a proxy and the proxies ip?

is this simple?

will i have trouble with firewalls etc?

"Rasmus Lerdorf" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> You can only get it if the proxy provides you with this data.  Most don't,
> so this is not a reliable approach.
>
> -Rasmus
>
> On Sat, 29 Jun 2002, JJ Harrison wrote:
>
> > I want to check to see if people have voted yet for a poll.
> >
> > How can I get the ip of a user from both behind a proxy and the proxies
ip?
> >
> > is this simple?
> >
> > will i have trouble with firewalls etc?
> >
> >
> > --
> > JJ Harrison
> > [EMAIL PROTECTED]
> > www.tececo.com
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>


--- End Message ---
--- Begin Message ---
There is no imagejpeg() call in the code snippet you provided.  And you
don't say how it is failing.  You haven't provided us with enough data to
answer this question.

-Rasmus

On Sat, 29 Jun 2002, andy wrote:

> Hi there,
>
> I would like to save a jpg into a blob field of mysql. The function
> underneath works fine if I read the image from the temporary destination
> where php did put it after uploading.
>
> My problem is, that I would like to do some funky stuff to the image like
> changing colors or adding watermarks. So I have several functions ahead
> before I used to store them successfully to the file system. Now I would
> like to store it to a blob field, but this does not work. Like I said it
> works to store the temp file, but not the other one. I guess it has to do
> with something regarding the imagejpeg function.
>
> Here is what I tryed:
>   #########################################
>    # save image to db into blob
>
>    // this does not work (outputImg is a the colorcorrected file)
>      $data = addslashes($outputImg);
>
>     // this one would work
>    # $data = addslashes(fread(fopen($picture_location, "r"),
> filesize($picture_location)));
>
>   $stmt ="
>    INSERT INTO test.picture_test
>     (file_name, file_type, picture)
>     VALUES
>     ('$name', '$picture_location_type', '$data')
>   ";
>   execute_stmt($stmt, $link);
>   #########################################
>
> Maybe some of you guy has a good idea on that.
>
> Thanx for any help,
>
> Andy
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
... sorry I thought it would be to much code.
Here is the complete code :

  $inputImg = ImageCreateFromJPEG($picture_location);

  # old size
  $srcX = imagesx($inputImg);
  $srcY = imagesy($inputImg);

   # new size
   $ratio = ($srcY / $dstY);
   $dstX = ($srcX / $ratio);

   $outputImg = ImageCreateTrueColor($maxX, $dstY);
   imagefill($outputImg, 0, 0, ImageColorAllocate($outputImg, 0, 0,0));
   imagecopyresampled($outputImg, $inputImg, (($maxX - $dstX) / 2),0,0,0,
$dstX, $dstY, $srcX, $srcY);

    #########################################
     # save image to db into blob

    // this does not work (outputImg is a the colorcorrected file)
       $data = addslashes($outputImg);

     // this one would work
    # $data = addslashes(fread(fopen($picture_location, "r"),
filesize($picture_location)));

      $stmt ="
    INSERT INTO test.picture_test
    (file_name, file_type, picture)
        VALUES
     ('$name', '$picture_location_type', '$data')
  ";
   execute_stmt($stmt, $link);
  #########################################


"Rasmus Lerdorf" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> There is no imagejpeg() call in the code snippet you provided.  And you
> don't say how it is failing.  You haven't provided us with enough data to
> answer this question.
>
> -Rasmus
>
> On Sat, 29 Jun 2002, andy wrote:
>
> > Hi there,
> >
> > I would like to save a jpg into a blob field of mysql. The function
> > underneath works fine if I read the image from the temporary destination
> > where php did put it after uploading.
> >
> > My problem is, that I would like to do some funky stuff to the image
like
> > changing colors or adding watermarks. So I have several functions ahead
> > before I used to store them successfully to the file system. Now I would
> > like to store it to a blob field, but this does not work. Like I said it
> > works to store the temp file, but not the other one. I guess it has to
do
> > with something regarding the imagejpeg function.
> >
> > Here is what I tryed:
> >   #########################################
> >    # save image to db into blob
> >
> >    // this does not work (outputImg is a the colorcorrected file)
> >      $data = addslashes($outputImg);
> >
> >     // this one would work
> >    # $data = addslashes(fread(fopen($picture_location, "r"),
> > filesize($picture_location)));
> >
> >   $stmt ="
> >    INSERT INTO test.picture_test
> >     (file_name, file_type, picture)
> >     VALUES
> >     ('$name', '$picture_location_type', '$data')
> >   ";
> >   execute_stmt($stmt, $link);
> >   #########################################
> >
> > Maybe some of you guy has a good idea on that.
> >
> > Thanx for any help,
> >
> > Andy
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
--
----------------------------------------------
http://www.globosapiens.net
Global Travellers Network


--- End Message ---
--- Begin Message ---
-----Original Message-----
> From: Peter J. Schoenster [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 29, 2002 1:27 AM
> To: [EMAIL PROTECTED]
> Subject: RE: [PHP] Keeping "Secrets" in PHP Files

> Yeah, you are assuming an environment that does
> not necessarily have to be. Why must one Apache
> server serve all users? Simply because that's
> the easiest way to do right out of the box?
> You have 2 scenarios as I see it:

> 1. Your own box -- no troubles other than the
> obvious
> 2. Virtual Server - One Apache for all users ...
> seems insecure
> 3. Virtual Server - One Apache for EACH user ...
> seems quite secure and experience confirms.

Not to be picky but you said there werwe 2 scenarios :-)

In any case, your #3 above works as long as each server runs in
its own unique group, which is shares with the customer.

> Peter

--
JR

--- End Message ---
--- Begin Message ---
I've tried everything I can think of to change a dallar sign in a string to
something else or to split the string on the $ but I can't the the
information that comes after the $.

Typical string contains: 1.2$General/ms1.zip

when I try:
        $new_string = preg_replace("/\$/", "%", $test_string);

or (trying to avoid specifying the $):
        $new_string = preg_replace("/(\d\.\d{1,2})\D(\w.*$)/", "\1%\2",
$test_string);

echo "new_string is $new_string"; prints new_string is 1.2

Has anyone solved this problem?

Thanx,

Bev

--- End Message ---
--- Begin Message ---
use single quotes: double quotes would confuse php with variable names.
it thinks that $General is a variable and replace it by it's empty content.
single quotes prevent php from evaluating the string:

$test_string = '1.2$General/ms1.zip'; 

single quotes on regex too (same reason). the backslash in this case
(\$) refers to perl regular expression syntax but does not take care of php !

$new_string = preg_replace('/\$/', "%", $test_string); 

ub


At 10:58 29.06.02 -0400, Beverly Steiner wrote:
>I've tried everything I can think of to change a dallar sign in a string to
>something else or to split the string on the $ but I can't the the
>information that comes after the $.
>
>Typical string contains: 1.2$General/ms1.zip
>
>when I try:
>       $new_string = preg_replace("/\$/", "%", $test_string);
>
>or (trying to avoid specifying the $):
>       $new_string = preg_replace("/(\d\.\d{1,2})\D(\w.*$)/", "\1%\2",
>$test_string);
>
>echo "new_string is $new_string"; prints new_string is 1.2
>
>Has anyone solved this problem?
>
>Thanx,
>
>Bev
>
>
>-- 
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

-- 
-----------------------------------------------
 Ulrich Borchers
 Brandenberger Straße 18, 41065 Mönchengladbach
 fon +49-2161-175883
 icq 1282868
-----------------------------------------------

--- End Message ---
--- Begin Message ---
On Saturday 29 June 2002 22:58, Beverly Steiner wrote:
> I've tried everything I can think of to change a dallar sign in a string to
> something else or to split the string on the $ but I can't the the
> information that comes after the $.
>
> Typical string contains: 1.2$General/ms1.zip
>
> when I try:
>       $new_string = preg_replace("/\$/", "%", $test_string);

Try:

  $new_string = preg_replace("/\\$/", "%", $test_string);

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Pity the meek, for they shall inherit the earth.
                -- Don Marquis
*/

--- End Message ---
--- Begin Message ---
Jason,

Thanx for your suggestion but I tried it and it didn't work.  I'm not sure
if it matters, but this running on NT.

Bev

-----Original Message-----
From: Jason Wong [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 29, 2002 12:05 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] need to change $ char in string


On Saturday 29 June 2002 22:58, Beverly Steiner wrote:
> I've tried everything I can think of to change a dallar sign in a string
to
> something else or to split the string on the $ but I can't the the
> information that comes after the $.
>
> Typical string contains: 1.2$General/ms1.zip
>
> when I try:
>       $new_string = preg_replace("/\$/", "%", $test_string);

Try:

  $new_string = preg_replace("/\\$/", "%", $test_string);

--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Pity the meek, for they shall inherit the earth.
                -- Don Marquis
*/


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

--- End Message ---
--- Begin Message ---
On Sunday 30 June 2002 01:24, Beverly Steiner wrote:

> Thanx for your suggestion but I tried it and it didn't work.  I'm not sure
> if it matters, but this running on NT.

Not sure whether NT has anything to do with it but it works for me :-) 

If you can't get the following code to work then you might want to check 
whether it is a known bug (http://bugs.php.net).

<?
$test_string = '1.2$General/ms1.zip';
$new_string = preg_replace("/\\$/", "%", $test_string);
echo "new_string is $new_string";
?>

But as someone has pointed out, you should be using single-quotes to prevent 
unwanted/unexpected variable expansion:

$new_string = preg_replace('/\$/', '%', $test_string);

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
All great discoveries are made by mistake.
                -- Young
*/

--- End Message ---
--- Begin Message ---
works for me on win2k
----- Original Message ----- 
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 29, 2002 6:43 PM
Subject: Re: [PHP] need to change $ char in string


On Sunday 30 June 2002 01:24, Beverly Steiner wrote:

> Thanx for your suggestion but I tried it and it didn't work.  I'm not sure
> if it matters, but this running on NT.

Not sure whether NT has anything to do with it but it works for me :-) 

If you can't get the following code to work then you might want to check 
whether it is a known bug (http://bugs.php.net).

<?
$test_string = '1.2$General/ms1.zip';
$new_string = preg_replace("/\\$/", "%", $test_string);
echo "new_string is $new_string";
?>

But as someone has pointed out, you should be using single-quotes to prevent 
unwanted/unexpected variable expansion:

$new_string = preg_replace('/\$/', '%', $test_string);

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
All great discoveries are made by mistake.
-- Young
*/


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




--- End Message ---
--- Begin Message ---
try double \\ to escape the special characters used by php for variables and
what not.  I think I read it here on a previous post.
Hope this helps
Hugh
----- Original Message -----
From: "Beverly Steiner" <[EMAIL PROTECTED]>
To: "PHP List" <[EMAIL PROTECTED]>
Sent: Saturday, June 29, 2002 7:58 AM
Subject: [PHP] need to change $ char in string


> I've tried everything I can think of to change a dallar sign in a string
to
> something else or to split the string on the $ but I can't the the
> information that comes after the $.
>
> Typical string contains: 1.2$General/ms1.zip
>
> when I try:
> $new_string = preg_replace("/\$/", "%", $test_string);
>
> or (trying to avoid specifying the $):
> $new_string = preg_replace("/(\d\.\d{1,2})\D(\w.*$)/", "\1%\2",
> $test_string);
>
> echo "new_string is $new_string"; prints new_string is 1.2
>
> Has anyone solved this problem?
>
> Thanx,
>
> Bev
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--- End Message ---
--- Begin Message ---
Hi,

Apologies if this question has already been asked in the past, but I have
only just registered for this list.

Does PHP in anyway support ASP style application-level variables in a
similair way to how standard sessions are used.

Though of implementing this as either files or database records but the
additional coding could be more error-prone or eat more system resources
than using a feature built into PHP itself.

I would be interested to hear other peoples views on this feature.

Lee

--- End Message ---
--- Begin Message ---
This seems to be the question of the question of the week. No, there are
no application level variables in PHP. You can set constants, either
through your web server, or maybe PHP.ini, but that's about it. 

I think the easiest way to implement something like this would be to use
the auto_append_file and auto_prepend_file settings of PHP.ini. Make
that file load the application variables from the database, and the
prepend file saves any changes...

---John Holmes...

> -----Original Message-----
> From: Lee [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 29, 2002 11:11 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] ASP style "application-level" variables
> 
> Hi,
> 
> Apologies if this question has already been asked in the past, but I
have
> only just registered for this list.
> 
> Does PHP in anyway support ASP style application-level variables in a
> similair way to how standard sessions are used.
> 
> Though of implementing this as either files or database records but
the
> additional coding could be more error-prone or eat more system
resources
> than using a feature built into PHP itself.
> 
> I would be interested to hear other peoples views on this feature.
> 
> Lee
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
> Make that file load the application variables from the database, and
the
> prepend file saves any changes...

errr...prepend loads...append save. Damn English language...

---John Holmes...

--- End Message ---
--- Begin Message ---
Lee,

Please check the archives before posting questions like this.  As John
stated, this question has been asked and answered this week. (I think it was
a thread just yesterday.)

It would have been much quicker for you to get your answer by mining the
archives than by posting it again here.

Thanks for your cooperation,
=C=

p.s. I accomplish applicaiton level variables by storing them in a table
called application in my application's database.  This way I can change them
on the fly and all my pages can see them.  I have objects that read them in
on the pages that need them.


*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*


-----Original Message-----
From: Lee [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 29, 2002 10:11 AM
To: [EMAIL PROTECTED]
Subject: [PHP] ASP style "application-level" variables


Hi,

Apologies if this question has already been asked in the past, but I have
only just registered for this list.

Does PHP in anyway support ASP style application-level variables in a
similair way to how standard sessions are used.

Though of implementing this as either files or database records but the
additional coding could be more error-prone or eat more system resources
than using a feature built into PHP itself.

I would be interested to hear other peoples views on this feature.

Lee


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


--- End Message ---
--- Begin Message ---
I have some popup menus and want the items in the menu to be populated from
a database. In this case I have a table that contains a listing of
departments. I have a page that I can go in and add/delete departments, and
want the changes to reflect in the menu the next time you go to the page.

I searched for examples and found this:

http://marc.theaimsgroup.com/?l=php-general&m=97628169623096&w=2

What is here is beyond my understanding, and seems like it is a little much
for what I need.

Here is what my database table looks like:

Departments
    department_id
    department_name

I just want to list the department name in the popup.


Thanks,
Mike

--- End Message ---
--- Begin Message ---
On Saturday 29 June 2002 23:41, Mike Tuller wrote:
> I have some popup menus and want the items in the menu to be populated from
> a database. In this case I have a table that contains a listing of
> departments. I have a page that I can go in and add/delete departments, and
> want the changes to reflect in the menu the next time you go to the page.
>
> I searched for examples and found this:
>
> http://marc.theaimsgroup.com/?l=php-general&m=97628169623096&w=2
>
> What is here is beyond my understanding, and seems like it is a little much
> for what I need.
>
> Here is what my database table looks like:
>
> Departments
>     department_id
>     department_name
>
> I just want to list the department name in the popup.

There are two things you need to know:

1) How to construct a select list in HTML
2) How to retrieve the info from the db

What are you having problems with? 

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
The only rose without thorns is friendship.
*/

--- End Message ---
--- Begin Message ---
Hi Mike,

Check out ADODB. It's a database abstraction layer for PHP that has
functions to do this. (php.weblogs.com)  Otherwise it's kinda easy to do
this, here's some psuedo-code that shoudl get you going.

<?PHP
// Make your connection to your database
// Select * from department
?>
<SELECT name='departmentID'>
<?PHP
//While !EOF
?>
<?PHP
<option value="<PHP echo $rs->fields['departmentID']; ?>"><PHP echo
$rs->fields['departmentName']; ?>
?>
<?PHP
// loop
?>
</SELECT>

=C=

*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*


-----Original Message-----
From: Mike Tuller [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 29, 2002 10:42 AM
To: php mailing list
Subject: [PHP] Populate Popup Menu from Database


I have some popup menus and want the items in the menu to be populated from
a database. In this case I have a table that contains a listing of
departments. I have a page that I can go in and add/delete departments, and
want the changes to reflect in the menu the next time you go to the page.

I searched for examples and found this:

http://marc.theaimsgroup.com/?l=php-general&m=97628169623096&w=2

What is here is beyond my understanding, and seems like it is a little much
for what I need.

Here is what my database table looks like:

Departments
    department_id
    department_name

I just want to list the department name in the popup.


Thanks,
Mike


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


--- End Message ---
--- Begin Message ---
Thanks. I thought the example I found was a little to complicated for
something like this.


> From: "Cal Evans" <[EMAIL PROTECTED]>
> Date: Sat, 29 Jun 2002 11:03:16 -0500
> To: "Mike Tuller" <[EMAIL PROTECTED]>, "php mailing list"
> <[EMAIL PROTECTED]>
> Subject: RE: [PHP] Populate Popup Menu from Database
> 
> Hi Mike,
> 
> Check out ADODB. It's a database abstraction layer for PHP that has
> functions to do this. (php.weblogs.com)  Otherwise it's kinda easy to do
> this, here's some psuedo-code that shoudl get you going.
> 
> <?PHP
> // Make your connection to your database
> // Select * from department
> ?>
> <SELECT name='departmentID'>
> <?PHP
> //While !EOF
> ?>
> <?PHP
> <option value="<PHP echo $rs->fields['departmentID']; ?>"><PHP echo
> $rs->fields['departmentName']; ?>
> ?>
> <?PHP
> // loop
> ?>
> </SELECT>
> 
> =C=
> 
> *
> * Cal Evans
> * Journeyman Programmer
> * Techno-Mage
> * http://www.calevans.com
> *
> 
> 
> -----Original Message-----
> From: Mike Tuller [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 29, 2002 10:42 AM
> To: php mailing list
> Subject: [PHP] Populate Popup Menu from Database
> 
> 
> I have some popup menus and want the items in the menu to be populated from
> a database. In this case I have a table that contains a listing of
> departments. I have a page that I can go in and add/delete departments, and
> want the changes to reflect in the menu the next time you go to the page.
> 
> I searched for examples and found this:
> 
> http://marc.theaimsgroup.com/?l=php-general&m=97628169623096&w=2
> 
> What is here is beyond my understanding, and seems like it is a little much
> for what I need.
> 
> Here is what my database table looks like:
> 
> Departments
>   department_id
>   department_name
> 
> I just want to list the department name in the popup.
> 
> 
> Thanks,
> Mike
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

--- End Message ---
--- Begin Message ---
I only ask questions if I have tried to do something myself already. I am
not looking for someone to do something for me. When I do ask a question
though, I feel I deserve at least a little respect. If you want to be an
ass, do it somewhere else.

> From: Jason Wong <[EMAIL PROTECTED]>
> Organization: Gremlins Associates
> Reply-To: [EMAIL PROTECTED]
> Date: Sat, 29 Jun 2002 23:54:22 +0800
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Populate Popup Menu from Database
> 
> On Saturday 29 June 2002 23:41, Mike Tuller wrote:
>> I have some popup menus and want the items in the menu to be populated from
>> a database. In this case I have a table that contains a listing of
>> departments. I have a page that I can go in and add/delete departments, and
>> want the changes to reflect in the menu the next time you go to the page.
>> 
>> I searched for examples and found this:
>> 
>> http://marc.theaimsgroup.com/?l=php-general&m=97628169623096&w=2
>> 
>> What is here is beyond my understanding, and seems like it is a little much
>> for what I need.
>> 
>> Here is what my database table looks like:
>> 
>> Departments
>>     department_id
>>     department_name
>> 
>> I just want to list the department name in the popup.
> 
> There are two things you need to know:
> 
> 1) How to construct a select list in HTML
> 2) How to retrieve the info from the db
> 
> What are you having problems with?
> 
> -- 
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> 
> /*
> The only rose without thorns is friendship.
> */
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

--- End Message ---
--- Begin Message ---
On Sunday 30 June 2002 00:31, Mike Tuller wrote:
> I only ask questions if I have tried to do something myself already. I am
> not looking for someone to do something for me. When I do ask a question
> though, I feel I deserve at least a little respect. If you want to be an
> ass, do it somewhere else.

Attitude! What part of my post offended you? I was merely stating what you 
need to know to be able to solve your problem. And then I asked which part 
you were having trouble with.

You have given no indication in your post as to what level of competence you 
have in PHP and HTML. The only hint was that the example you quoted was 
beyond your understanding.

You have given no indication of what you have done and did or didn't work.

So how is one supposed to respond to your post?

a) give you a solution, which may or may not be beyond your understanding?
b) or prod you along the right direction with a request for more information?

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
The world is coming to an end--save your buffers!
*/

--- End Message ---
--- Begin Message ---
Mike Tuller wrote:

>I only ask questions if I have tried to do something myself already. I am
>not looking for someone to do something for me. When I do ask a question
>though, I feel I deserve at least a little respect. If you want to be an
>ass, do it somewhere else.
>
It seems *you* are the one being an ass and needing to "do it somewhere 
else."

If you can't have enough respect for people trying to help you by 
answering the simplest of questions (that should have been given in your 
original question anyway), you don't deserve an answer.

Here are Mr. Wong's questions again (very appropriate questions at 
that). Perhaps if you offer him a sincere apology, thank him for his 
time, and *answer* *his* *questions*, he might be willing to forgive 
your poor attitude and offer you some help.

>>There are two things you need to know:
>>
>>1) How to construct a select list in HTML
>>2) How to retrieve the info from the db
>>
>>What are you having problems with?
>>
If you don't know a damn thing, that's fine. An appropriate answer would 
be, "I neither know how to construct a select list in HTML nor how to 
retrieve information from a database."

Chris

--- End Message ---
--- Begin Message ---
To let everyone know, I did apologize to Mr. Wong. I misunderstood what he
was trying to ask me. I took it as he was saying "It's easy, what is "your"
problem" rather than "What "is" your problem" .

> From: Chris Shiflett <[EMAIL PROTECTED]>
> Date: Sat, 29 Jun 2002 13:50:14 -0500
> To: Mike Tuller <[EMAIL PROTECTED]>
> Cc: php mailing list <[EMAIL PROTECTED]>, Jason Wong
> <[EMAIL PROTECTED]>
> Subject: Re: [PHP] Populate Popup Menu from Database
> 
> Mike Tuller wrote:
> 
>> I only ask questions if I have tried to do something myself already. I am
>> not looking for someone to do something for me. When I do ask a question
>> though, I feel I deserve at least a little respect. If you want to be an
>> ass, do it somewhere else.
>> 
> It seems *you* are the one being an ass and needing to "do it somewhere
> else."
> 
> If you can't have enough respect for people trying to help you by
> answering the simplest of questions (that should have been given in your
> original question anyway), you don't deserve an answer.
> 
> Here are Mr. Wong's questions again (very appropriate questions at
> that). Perhaps if you offer him a sincere apology, thank him for his
> time, and *answer* *his* *questions*, he might be willing to forgive
> your poor attitude and offer you some help.
> 
>>> There are two things you need to know:
>>> 
>>> 1) How to construct a select list in HTML
>>> 2) How to retrieve the info from the db
>>> 
>>> What are you having problems with?
>>> 
> If you don't know a damn thing, that's fine. An appropriate answer would
> be, "I neither know how to construct a select list in HTML nor how to
> retrieve information from a database."
> 
> Chris
> 

--- End Message ---
--- Begin Message ---
Thanks alot,

I changed the reporting level. I found it myself later on. Just was a bit to
quick when posting this question.

Sacha Telgenhof

"John Holmes" <[EMAIL PROTECTED]> wrote in message
news:000d01c21f0c$de789bf0$b402a8c0@mango...
> > Maybe it's already discussed here, but PHP is generating errors of
> > undefined
> > constants. These constants are defined in my scripts. Als the
> superglobal
> > $_ENV is empty.
>
> Use quotes when using associative arrays.
>
> $_ENV['something'] rather than $_ENV[something]
>
> The warnings have always been there, PHP 4.2 just defaults to a higher
> error reporting level, so now you notice them. The problem comes from
> PHP looking for a constant called "something" and when it's not found,
> it issues a warning. Then it assumes you meant to use a string and tries
> it that way.
>
> You can adjust the error reporting in PHP.ini or with the
> error_reporting() function.
>
> ---John Holmes...
>


--- End Message ---
--- Begin Message ---
Joshua Alexander wrote:

> "It seems pretty straightforward to me." is more responsible than 
> "It's pretty straightforward." Nice time to be changing your story ;) 

Please check my original message. I said "I think it's pretty 
straightforward". That implies subjectivity.

>
>> Anyway, thank you for your input on this thread. THAT was really 
>> helpful.
>
>
> It didn't seem straightforward to the original writer, or else why the 
> question... I think a more helpful response at that point is to ask 
> questions, rather than suggest that the person simply "write it".

The typical answer I expected was something along the lines of "it's not 
very straightforward because I need alpha matting/color calibration/this 
strange type of gradient/a gradient according to the absolute color of 
the sky above the cloud limit in the geographical location of the person 
who reaches my page" or whatever the problem WHICH MADE THIS 
NON-TRIVIAL. A gradient in the most generic form is pretty trivial (i.e. 
straightforward) to render on anybody's standards, AFAIK.

>
> There seems to be some hostility and impatience here toward new users 
> who aren't as familiar with how to ask for help. If this exchange 
> prompts anyone to examine themselves and respond (or ask) in more 
> gentle ways, I think my input will have definitely been helpful.

Well, I'm deeply moved by your concern - I don't think I was either 
hostile or impatient however - I was just stating the obvious and 
implying a question (why isn't it straightforward). And just for the 
record, I didn't even assume Mr. Matilla was a new user.

Bogdan


--- End Message ---
--- Begin Message ---
> On Saturday 29 June 2002 18:02, Dan Tappin wrote:
>> I am setting up a login section of my site using sessions.  I have the
>> login working with and without cookies enabled.  I do not want to restrict
>> my users be requiring cookies.
>> 
>> The problem is that I can't seem to get PHP to auto append the session id
>> to the relative URLs on the page.
>> 
>> I have the following PHP settings:
>> 
>> php_value session.use_cookies 0
>> php_value session.use_trans_sid 1
>> 
>> I also had these setings in my php.ini file.
> 
> Was your php compiled with '--enable-trans-sid' ?

Yes.  I checked that.

Dan


--- End Message ---
--- Begin Message ---
This is a follow-up to another thread - [PHP] session.use_trans_sid

I am setting up a login section of my site using sessions.  I have the login
working with and without cookies enabled.  I do not want to restrict my
users be requiring cookies.

Here is my /login/login.php file which takes the results of the user login
form:

<?

session_start();

if ($username && $password)
{

// Here is a MySQL query to verify that the username and password are valid

$num_rows = mysql_num_rows($login_result);

if ($num_rows >0 )
    {
        $row = mysql_fetch_array($login_result);
        session_register("id");  // I register the user id for later use
        $id = $row["id"];   // I set the user id

        // Once the user is verified I redirect to the main user page

        $redirect =
"http://www.fakeserver.com/login/home/index.php?sid=".session_id();
        header("Location: $redirect");
    };
};
?>


The problem is that I can't seem to get PHP to auto append the session id to
the relative URLs on the following pages.

Here is a include that I have added to each subsequent page to verify that
this is a valid user:

<?

// Now this is perhaps part of the issue.  I can't get these pages to keep
the session id unless I call session_name('sid') first.  I changed PHPSESSID
to SID in the config files.  If I comment out this my session variable $id
which I use to check for a valid session gets lost and my logout() function
triggers.

session_name('sid');

session_start();

if(!$id) {

    logout();  // My logout function that clears the session variables and
destroys the session

};

// The rest of the HTML...

?>

The problem is that the SID is not getting automatically added to the URL's.
If I allow cookies all is fine.  I can go from page to page in my 'secure'
login section and the $id session variable is accessible and the
verification works fine.  If I disable cookies the auto addition of the SID
does not happen at all.  The first page is fine because I hard coded the SID
into the header() call.  If I manual add the SID to local links it works as
well and I am not logged out.

This is driving me crazy!

I have the following PHP settings in my Apache VH:

php_value session.use_cookies 0  // This seems to have no effect on the
trans_sid issue as I have tried it both ways
php_value session.use_trans_sid 1

I also had these setings in my php.ini file.

Am I missing something basic about sessions here?  I have looked all over
the web for a simular problem and I can't find one.  Help!! :^)

Thanks,

Dan
    

--- End Message ---
--- Begin Message ---
Hi,

I want to write function which change variable in ie. config.php file ...
Here is code:

<?

include "config.php";

$file = fopen("config.php", "w+");

$content = fread($file, filesize("config.php"));

$content = str_replace("\$option['test'] = \"" . $option['test'] . "\";",
"\$option['test'] = \"po tescie\";", $content);

fwrite($file, $content);

?>

and config.php:

<?

$option['test'] = "test";

?>

and it's doesn't work :( ... when I run script, it clear config.php and
nothing else ... where is my fault?


--- End Message ---
--- Begin Message ---
How do I limit the number of decimal places returned in this query?

<?php

$result2 = mysql_query("SELECT sum(purchase_price) as total FROM assets
where order_number='$order_number'");

while(list($order_total) = mysql_fetch_row($result2))

{

print ("$order_total");

}

?>



--- End Message ---
--- Begin Message ---
round($order_total), floor("), ceil(") are some options.
> How do I limit the number of decimal places returned in this query?
>
> <?php
>
> $result2 = mysql_query("SELECT sum(purchase_price) as total FROM assets
> where order_number='$order_number'");
>
> while(list($order_total) = mysql_fetch_row($result2))
>
> {
>
> print ("$order_total");
>
> }
>
> ?>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-Pushkar S. Pradhan

--- End Message ---
--- Begin Message ---
> How do I limit the number of decimal places returned in this query?
> 
> <?php
> 
> $result2 = mysql_query("SELECT sum(purchase_price) as total FROM
assets
> where order_number='$order_number'");
> 
> while(list($order_total) = mysql_fetch_row($result2))
> 
> {
> 
> print ("$order_total");

If you were using the correct column type in MySQL, DECIMAL, you
shouldn't have to worry about the decimal places. Otherwise, you can use
number_format() on $order_total.

Also, the while() loop isn't needed, since only one row is returned from
a query like that without a GROUP BY clause. Also, you don't need the
quotes around $order_total when printing it out. 

---John Holmes...

--- End Message ---
--- Begin Message ---
Hello, Folks,

My apologies if this has been asked a thousand times. I've just joined the
list.

I can't find any information on passing JavaScript variables to PHP on the
same page (i.e. not through the POST information of a submitted form). Is
this because it's not possible?

To take the load off the server, I'm trying to do a bunch of string
manipulations and loops in JavaScript and then hand that info off to PHP
once it's done.

Any insight is appreciated! Thanks,
Jed

--- End Message ---
--- Begin Message ---
Not possible. You must refresh the page to send something back to PHP.
Only workaround is using a hidden frame or layer and refreshing that...

---John Holmes...

> -----Original Message-----
> From: Jed Verity [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 29, 2002 3:14 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Javascript to PHP?
> 
> Hello, Folks,
> 
> My apologies if this has been asked a thousand times. I've just joined
the
> list.
> 
> I can't find any information on passing JavaScript variables to PHP on
the
> same page (i.e. not through the POST information of a submitted form).
Is
> this because it's not possible?
> 
> To take the load off the server, I'm trying to do a bunch of string
> manipulations and loops in JavaScript and then hand that info off to
PHP
> once it's done.
> 
> Any insight is appreciated! Thanks,
> Jed
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
I've done this stuff recently. I need to pass whole arrays betn. php and
Javascript (2-way), here is some code:

// PHP var. to JS
function arrFromStr (str2convert) {  // make an array from string
   arr = new Array();
   var posOfQt1   = str2convert.indexOf('\"');
   var posOfQt2   = str2convert.indexOf('\"', posOfQt1+1);
   i = 0;
   while(posOfQt1 != -1) {
      arr[i] = str2convert.substring(posOfQt1+1, posOfQt2);
      i++;
      posOfQt1 = posOfQt2;
      posOfQt1   = str2convert.indexOf('\"', posOfQt1+1);
      posOfQt2   = str2convert.indexOf('\"', posOfQt1+1);
   }
   return arr;
}
Call this function like this:
layerDesStr  = '<?=serialize($layerDes[0])?>';
layerDes[0]  = arrFromStr(layerDesStr);

In case you have a variable don't serialize, just do
myJSvar = <?=$myPHPvar?>;
JS variables can be sent to PHP by including them in html forms, nothing
special about it.
> Hello, Folks,
>
> My apologies if this has been asked a thousand times. I've just joined the
> list.
>
> I can't find any information on passing JavaScript variables to PHP on the
> same page (i.e. not through the POST information of a submitted form). Is
> this because it's not possible?
>
> To take the load off the server, I'm trying to do a bunch of string
> manipulations and loops in JavaScript and then hand that info off to PHP
> once it's done.
>
> Any insight is appreciated! Thanks,
> Jed
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-Pushkar S. Pradhan

--- End Message ---
--- Begin Message ---
That's what I was afraid of. It makes sense, of course...I was just hoping
there was some kind of hack. Thanks for responding!
Jed

I liked it when John Holmes wrote this to me:

> Not possible. You must refresh the page to send something back to PHP.
> Only workaround is using a hidden frame or layer and refreshing that...
> 
> ---John Holmes...
> 
>> -----Original Message-----
>> From: Jed Verity [mailto:[EMAIL PROTECTED]]
>> Sent: Saturday, June 29, 2002 3:14 PM
>> To: [EMAIL PROTECTED]
>> Subject: [PHP] Javascript to PHP?
>> 
>> Hello, Folks,
>> 
>> My apologies if this has been asked a thousand times. I've just joined
> the
>> list.
>> 
>> I can't find any information on passing JavaScript variables to PHP on
> the
>> same page (i.e. not through the POST information of a submitted form).
> Is
>> this because it's not possible?
>> 
>> To take the load off the server, I'm trying to do a bunch of string
>> manipulations and loops in JavaScript and then hand that info off to
> PHP
>> once it's done.
>> 
>> Any insight is appreciated! Thanks,
>> Jed
>> 
>> 
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


--- End Message ---
--- Begin Message ---
Jed Verity wrote:

>I can't find any information on passing JavaScript variables to PHP on the
>same page (i.e. not through the POST information of a submitted form). Is
>this because it's not possible?
>
Basically, this is not possible.

A common area of confusion to those new to Web programming is the 
distinction between client-side and server-side code. PHP is an example 
of a server-side scripting language, while JavaScript is client-side. To 
PHP, anything that is not PHP is simply output. It doesn't matter if the 
output is HTML, JavaScript, XML, an image, etc. - it's all "not PHP."

When a user requests a PHP script, the PHP part of the script is 
executed prior to the output being sent to the client. Remember, the 
output may contain JavaScript. Once the output reaches the browser, the 
browser will attempt to render the HTML, execute the JavaScript, and 
whatever else is appropriate. So, to get back to your question, you are 
wanting to know how to have the browser (which is executing the 
JavaScript) be able to send a JavaScript variable to PHP (which could be 
thousands of miles away on whatever Web server the page was obtained 
from) "on the same page," which means you want to be able to do this 
without communicating back to the Web server.

So, your question can be summarized into:

"How can my browser send data back to the Web server without any further 
communication with the Web server?"

Hopefully that explains how it is impossible.

The terms server-side and client-side are ignored by most people, 
understandably, because this industry is littered with useless terms 
that do little to describe what is really happening (in the case of "Web 
services," the term is actually misleading in my opinion). However, 
these terms are very descriptive, and once you can begin to understand 
which code is executed on the server-side (by the Web server prior to 
sending the response to the Web client) and which code is executed on 
the client-side (by the Web client after receiving the response from the 
Web server), all of these types of questions will make more sense to you.

Hope that gives a good description of the difference and can help you 
solve whatever problem you're currently working on.

Chris

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

 > My apologies if this has been asked a thousand times. I've 
 > just joined the list.

I has, but you get that...

 > I can't find any information on passing JavaScript variables 
 > to PHP on the same page (i.e. not through the POST information of a 
 > submitted form). Is this because it's not possible?

Short answer is no.  PHP is server-side, Javascript is client-side.  You
can get variables from php to javascript when your php generates the
page to be sent to the browser but you can only get variables back from
php when you use browser to server communications (that's usually a form
- be it get or post method, or a cookie).

 > To take the load off the server, I'm trying to do a bunch of string
 > manipulations and loops in JavaScript and then hand that 
 > info off to PHP once it's done.

You'll need to create all the javascript from you php page as it
generates and then wait for it all to be done client-side and submitted
back to the server.

CYA, Dave



--- End Message ---
--- Begin Message ---
Or setting a cookie in JavaScript. It will be transmitted on the next page
request.

-----Original Message-----
From: John Holmes [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 29, 2002 3:30 PM
To: 'Jed Verity'; [EMAIL PROTECTED]
Subject: RE: [PHP] Javascript to PHP?


Not possible. You must refresh the page to send something back to PHP.
Only workaround is using a hidden frame or layer and refreshing that...


--- End Message ---
--- Begin Message ---
Hello, Chris,

Many thanks for the thorough description. It does make sense, of course...I
was just hoping that there was some kind of funky loophole that small brains
like mine couldn't comprehend.

Thanks again!
Jed

I liked it when Chris Shiflett wrote this to me:

> Jed Verity wrote:
> 
>> I can't find any information on passing JavaScript variables to PHP on the
>> same page (i.e. not through the POST information of a submitted form). Is
>> this because it's not possible?
>> 
> Basically, this is not possible.
> 
> A common area of confusion to those new to Web programming is the
> distinction between client-side and server-side code. PHP is an example
> of a server-side scripting language, while JavaScript is client-side. To
> PHP, anything that is not PHP is simply output. It doesn't matter if the
> output is HTML, JavaScript, XML, an image, etc. - it's all "not PHP."
> 
> When a user requests a PHP script, the PHP part of the script is
> executed prior to the output being sent to the client. Remember, the
> output may contain JavaScript. Once the output reaches the browser, the
> browser will attempt to render the HTML, execute the JavaScript, and
> whatever else is appropriate. So, to get back to your question, you are
> wanting to know how to have the browser (which is executing the
> JavaScript) be able to send a JavaScript variable to PHP (which could be
> thousands of miles away on whatever Web server the page was obtained
> from) "on the same page," which means you want to be able to do this
> without communicating back to the Web server.
> 
> So, your question can be summarized into:
> 
> "How can my browser send data back to the Web server without any further
> communication with the Web server?"
> 
> Hopefully that explains how it is impossible.
> 
> The terms server-side and client-side are ignored by most people,
> understandably, because this industry is littered with useless terms
> that do little to describe what is really happening (in the case of "Web
> services," the term is actually misleading in my opinion). However,
> these terms are very descriptive, and once you can begin to understand
> which code is executed on the server-side (by the Web server prior to
> sending the response to the Web client) and which code is executed on
> the client-side (by the Web client after receiving the response from the
> Web server), all of these types of questions will make more sense to you.
> 
> Hope that gives a good description of the difference and can help you
> solve whatever problem you're currently working on.
> 
> Chris
> 
> 

--- End Message ---
--- Begin Message ---
You might be able to pass them as a cookie.

Bruce Karstedt
President
Technology Consulting Associates, Ltd.
Tel: 847-735-9488
Fax: 847-735-9474


-----Original Message-----
From: Jed Verity [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 29, 2002 2:59 PM
To: Chris Shiflett
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Javascript to PHP?
Importance: Low


Hello, Chris,

Many thanks for the thorough description. It does make sense, of course...I
was just hoping that there was some kind of funky loophole that small brains
like mine couldn't comprehend.

Thanks again!
Jed

I liked it when Chris Shiflett wrote this to me:

> Jed Verity wrote:
>
>> I can't find any information on passing JavaScript variables to PHP on
the
>> same page (i.e. not through the POST information of a submitted form). Is
>> this because it's not possible?
>>
> Basically, this is not possible.
>
> A common area of confusion to those new to Web programming is the
> distinction between client-side and server-side code. PHP is an example
> of a server-side scripting language, while JavaScript is client-side. To
> PHP, anything that is not PHP is simply output. It doesn't matter if the
> output is HTML, JavaScript, XML, an image, etc. - it's all "not PHP."
>
> When a user requests a PHP script, the PHP part of the script is
> executed prior to the output being sent to the client. Remember, the
> output may contain JavaScript. Once the output reaches the browser, the
> browser will attempt to render the HTML, execute the JavaScript, and
> whatever else is appropriate. So, to get back to your question, you are
> wanting to know how to have the browser (which is executing the
> JavaScript) be able to send a JavaScript variable to PHP (which could be
> thousands of miles away on whatever Web server the page was obtained
> from) "on the same page," which means you want to be able to do this
> without communicating back to the Web server.
>
> So, your question can be summarized into:
>
> "How can my browser send data back to the Web server without any further
> communication with the Web server?"
>
> Hopefully that explains how it is impossible.
>
> The terms server-side and client-side are ignored by most people,
> understandably, because this industry is littered with useless terms
> that do little to describe what is really happening (in the case of "Web
> services," the term is actually misleading in my opinion). However,
> these terms are very descriptive, and once you can begin to understand
> which code is executed on the server-side (by the Web server prior to
> sending the response to the Web client) and which code is executed on
> the client-side (by the Web client after receiving the response from the
> Web server), all of these types of questions will make more sense to you.
>
> Hope that gives a good description of the difference and can help you
> solve whatever problem you're currently working on.
>
> Chris
>
>


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

--- End Message ---
--- Begin Message ---
On Sat, 29 Jun 2002 16:58:50 -0300, Jed Verity wrote:
>Hello, Chris,
>
>Many thanks for the thorough description. It does make sense, of
>course...I
>was just hoping that there was some kind of funky loophole that
>small brains
>like mine couldn't comprehend.

well if it's one-way only communication, you could load an image in
javascript that is really a php page. that way you can send
information to a php script without the browser reloading. there's
probably other ways that a javascript guru could come up with (maybe
loading content into an invisible layer??) this isn't the best place
to be asking a javascript question tho.

hth.
- Mark

--- End Message ---
--- Begin Message ---
Hi,

I need to generate RTF files from within PHP scripts based on user 
input.   Do you know of any package to do the trick ?

Perhaps external one, for ex. generate a XML version and feed it into an 
external converter.

The rtf would have header/footer, ocasional images and tables.

Thanks.



--- End Message ---
--- Begin Message ---
check this out:
http://www.phpbuilder.com/columns/nair20020523.php3

Mirza


--- End Message ---
--- Begin Message ---
Search before you post. I don't know the answer, but this turned up on
google when searching for "generate rtf with PHP"

http://paggard.dlight.ru/rtf_gen/

Yeah, it costs, but it looks good. Help a programmer out!

I'm sure there are others. Look on hotscripts.com and sourceforge.net

---John Holmes...

> -----Original Message-----
> From: Mario Bittencourt [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 29, 2002 3:37 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Generating RTF on the fly
> 
> Hi,
> 
> I need to generate RTF files from within PHP scripts based on user
> input.   Do you know of any package to do the trick ?
> 
> Perhaps external one, for ex. generate a XML version and feed it into
an
> external converter.
> 
> The rtf would have header/footer, ocasional images and tables.
> 
> Thanks.
> 
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


--- End Message ---
--- Begin Message ---
On Saturday 29 June 2002 09:37 pm, Mario Bittencourt wrote:

> I need to generate RTF files from within PHP scripts based on user
> input.   Do you know of any package to do the trick ?
>

Besides the package already named, you can also just read an rtf template file 
and use str_replace.. It's plain ascii after all.  Not as good as generating, 
but quite usable for a quick hack.

Gerhard
--- End Message ---
--- Begin Message ---
Hello,

On 06/29/2002 04:37 PM, Mario Bittencourt wrote:
> Hi,
> 
> I need to generate RTF files from within PHP scripts based on user 
> input.   Do you know of any package to do the trick ?

If you are running under Windows you may use COM objects to convert HTML 
into RTF. You may want to try this PHP class for that:

http://www.phpclasses.org/browse.html/package/388.html






-- 

Regards,
Manuel Lemos

--- End Message ---
--- Begin Message ---
Hello Again, Folks,

I've been testing this for a while and keep coming up with mixed results. In
general, is it faster and more efficient to query a MySQL database once with
a large SQL select statement and then loop through the huge resulting table?
Or does it make better sense to perform a number of smaller queries with
smaller resulting tables?

This is the kind of stuff they just don't seem to talk about in the manuals.
Any insight is appreciated. Sorry for the ignorant question!

Jed

--- End Message ---
--- Begin Message ---
Depends what you're after. Your query should always return exactly the
data you are after. Your tables should be arranged so that is possible.

---John Holmes...

> -----Original Message-----
> From: Jed Verity [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, June 29, 2002 5:10 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Newbie Q: Fetching vs. Looping
> 
> Hello Again, Folks,
> 
> I've been testing this for a while and keep coming up with mixed
results.
> In
> general, is it faster and more efficient to query a MySQL database
once
> with
> a large SQL select statement and then loop through the huge resulting
> table?
> Or does it make better sense to perform a number of smaller queries
with
> smaller resulting tables?
> 
> This is the kind of stuff they just don't seem to talk about in the
> manuals.
> Any insight is appreciated. Sorry for the ignorant question!
> 
> Jed
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Jed Verity wrote:

>In general, is it faster and more efficient to query a MySQL database once with
>a large SQL select statement and then loop through the huge resulting table?
>Or does it make better sense to perform a number of smaller queries with
>smaller resulting tables?
>
This is a hard question to give an answer to. It depends largely on the 
amount of data you're talking about, the amount of memory on the machine 
your code is executing from, whether you are using persistent database 
connections, etc.

In general, if you use persistent database connections, each additional 
query after the first will be quite fast. I'm sure your question stems 
from seeing someone say that queries are the most common bottleneck for 
Web applications, and this is true to a point.

If the one query you speak of is huge, try some tests and see how much 
memory PHP has to use to maintain that in memory. Consider that multiple 
requests during the time that PHP is "holding" that data in memory will 
result in a pretty decent chunk of memory being used. If you have 
endless amounts of memory (some huge unix machine with 20+ GB of RAM), I 
would say go for the one query method. It is definitely going to be 
faster, so long as you have enough memory to handle it. In most cases, 
if your approach ends up running your machine out of memory under heavy 
load, it would be a poor approach, because it would end up slowing 
*everything* down.

So, maybe that gives you some things to think about. Maybe someone else 
can come up with a more conclusive answer.

In summation:
1) using memory to keep *all* database results can improve performance 
if you have plenty of memory to handle this approach
2) if not, try very specific queries that retrieve just the data you 
need, and carefully free all results as you finish - also try to use 
persistent connections if you forsee your site being under heavy load.

I personally take approach #2, because most of my environments have had 
sane (less than 5 GB) amounts of memory. I *think* this method would be 
more appropriate for most people, even though it seems like you end up 
hitting the database a lot. I've generally gotten extraordinary 
performance (page execution takes less than a tentth of a second 
searching through a database with 50,000 records) from a multi-homed Web 
host with PHP/MySQL, even with 30,000+ transactions/day. It's also more 
difficult to get specific data sets with one query; that approach 
usually requires that you have to take a greatest common denominator 
style approach and end up with way more data than you really need.

I'd be curious to see some other opinions. There's mine. :)

Chris

--- End Message ---
--- Begin Message ---
On Sat, 29 Jun 2002, Chris Shiflett wrote:

> 2) if not, try very specific queries that retrieve just the data you need,
> and carefully free all results as you finish - also try to use persistent
> connections if you forsee your site being under heavy load.

Something I haven't picked up in my reading of the manual:

Is a free required for every query?  Or can I go connect, query, query, 
query, free, close?

--- End Message ---
--- Begin Message ---
Duncan Hill wrote:

>Is a free required for every query?  Or can I go connect, query, query, 
>query, free, close?
>

You never have to free your results if you don't want to. As I 
understand it, doing so simply frees up the memory that is being taken 
up by the result set ($result in most examples). Whenever your script 
finishes executing, all memory associated with it will be freed anyway. 
Explicitly doing so simply allows this memory to be freed up sooner. It 
is definitely beneficial to always free your result set when you're 
finished with it, but you'll be hard-pressed to notice a difference, to 
be honest.

Chris


--- End Message ---
--- Begin Message ---
On Sat, 29 Jun 2002, Chris Shiflett wrote:

> Duncan Hill wrote:
> 
> >Is a free required for every query?  Or can I go connect, query, query, 
> >query, free, close?
> >
> 
> You never have to free your results if you don't want to. As I 
> understand it, doing so simply frees up the memory that is being taken 

*tip*  Ta.  Good programming practice then.

--- End Message ---
--- Begin Message ---
I am *very* new to PHP, so this may seem like a stupid question...  I am 
trying to generate dynamic drop-down lists for use in an HTML form, but 
I have done something wrong with my code.  Instead of getting one list 
box with three options, I am getting three list boxes with one option. 
I have included this piece of my code...  Can anyone help???


<?
$link = mysql_connect("localhost", "user", "pass");
mysql_select_db("my_db", $link);

$result = mysql_query("SELECT SKU, Description, Retail FROM linecard 
WHERE sku=61 or sku=239 or sku=318", $link);
$num_rows = mysql_num_rows($result);

if($num_rows) {
        while($row = mysql_fetch_row($result))

        {
           print("<select name=\"test\">");
           print("<option value=\"$row[0]-$row[1]-$row[2]\">$row[1] - 
\$$row[2]</option><br>");
           print("</select>");

        }

      } else {
        print("<option value=\"\">No Parts Created Yet</option>");
      }
?>

--- End Message ---
--- Begin Message ---
On Saturday, June 29, 2002 at 10:03:16 PM, Chase wrote:
> I am *very* new to PHP, so this may seem like a stupid question...  I am
> trying to generate dynamic drop-down lists for use in an HTML form, but 
> I have done something wrong with my code.  Instead of getting one list 
> box with three options, I am getting three list boxes with one option. 
> I have included this piece of my code...  Can anyone help???

Yes, you have the select open and close tags inside the loop. Move them either
side as follows...

<?
$link = mysql_connect("localhost", "user", "pass");
mysql_select_db("my_db", $link);

$result = mysql_query("SELECT SKU, Description, Retail FROM linecard
WHERE sku=61 or sku=239 or sku=318", $link);
$num_rows = mysql_num_rows($result);

if($num_rows) {
        print("<select name=\"test\">");
        while($row = mysql_fetch_row($result))

        {
           print("<option value=\"$row[0]-$row[1]-$row[2]\">$row[1] -
\$$row[2]</option><br>");

        }
        print("</select>");

      } else {
        print("<option value=\"\">No Parts Created Yet</option>");
      }
?>

-- 
Stuart

--- End Message ---
--- Begin Message ---
Thank you Stuart!!  I feel like an idiot...  I had tried moving one or 
the other outside the loop, but not both...  Thank you again!!

Chase

Stuart Dallas wrote:

> On Saturday, June 29, 2002 at 10:03:16 PM, Chase wrote:
> 
>>I am *very* new to PHP, so this may seem like a stupid question...  I am
>>trying to generate dynamic drop-down lists for use in an HTML form, but 
>>I have done something wrong with my code.  Instead of getting one list 
>>box with three options, I am getting three list boxes with one option. 
>>I have included this piece of my code...  Can anyone help???
>>
> 
> Yes, you have the select open and close tags inside the loop. Move them either
> side as follows...
> 
> <?
> $link = mysql_connect("localhost", "user", "pass");
> mysql_select_db("my_db", $link);
> 
> $result = mysql_query("SELECT SKU, Description, Retail FROM linecard
> WHERE sku=61 or sku=239 or sku=318", $link);
> $num_rows = mysql_num_rows($result);
> 
> if($num_rows) {
>         print("<select name=\"test\">");
>         while($row = mysql_fetch_row($result))
> 
>         {
>            print("<option value=\"$row[0]-$row[1]-$row[2]\">$row[1] -
> \$$row[2]</option><br>");
> 
>         }
>         print("</select>");
> 
>       } else {
>         print("<option value=\"\">No Parts Created Yet</option>");
>       }
> ?>
> 

--- End Message ---
--- Begin Message ---
Hi All,
I've stumped myself here.  In a nutshell, I have a function that returns my
array based on a SQL query and here's the code:

-------------begin code-------------------
function getCourses($UID)
 {
 global $link;
 $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U,
tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID =
$UID", $link );
 if ( ! $result )
  die ( "getRow fatal error: ".mysql_error() );
 return mysql_fetch_array( $result );
 }
------------end code ----------------

I call this from a PHP page with the following code:

------------begin code--------------
$myCourses = getCourses($session[id]);
foreach ($myCourses as $value)
 {
 print "<br>$value";
 }
------------end code---------------

Now, when I test the SQL from my function directly on the database, it
returns just want I want it to return but it isn't working that way on my
PHP page. For results where there is a single entry, I am getting the same
entry TWICE and for records with more than a single entry I am getting ONLY
the FIRST entry TWICE.

Now I know my SQL code is correct (I am testing it against a MySQL database
using MySQL-Front) so I suspect I'm doing something stupid in my foreach
loop.

I'm hoping someone will spot my dumb mistake.  Thanks very much for any help
at all on this.

....Brad


--- End Message ---
--- Begin Message ---
At 3:27 PM -0700 6/29/02, Brad Melendy wrote:
>Hi All,
>I've stumped myself here.  In a nutshell, I have a function that returns my
>array based on a SQL query and here's the code:
>
>-------------begin code-------------------
>function getCourses($UID)
>  {
>  global $link;
>  $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U,
>tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID =
>$UID", $link );
>  if ( ! $result )
>   die ( "getRow fatal error: ".mysql_error() );
>  return mysql_fetch_array( $result );
>  }
>------------end code ----------------
>
>I call this from a PHP page with the following code:
>
>------------begin code--------------
>$myCourses = getCourses($session[id]);
>foreach ($myCourses as $value)
>  {
>  print "<br>$value";
>  }
>------------end code---------------
>
>Now, when I test the SQL from my function directly on the database, it
>returns just want I want it to return but it isn't working that way on my
>PHP page. For results where there is a single entry, I am getting the same
>entry TWICE and for records with more than a single entry I am getting ONLY
>the FIRST entry TWICE.
>
>Now I know my SQL code is correct (I am testing it against a MySQL database
>using MySQL-Front) so I suspect I'm doing something stupid in my foreach
>loop.


I think your problem lies in a misunderstanding of the 
mysql_fetch_array() function. It doesn't return the entire result set 
in an array - just one record at a time. You can fix this in one of 
two ways:

(1) Loop though the entire result set in your function:

    function getCourses($UID)
     {
      global $link;

      $ResultSet = array();

      $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, tblusers U,
       tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID =
       $UID", $link );

      if ( ! $result )
       die ( "getRow fatal error: ".mysql_error() );

      while ($Row = mysql_fetch_array( $result ))
      {
       $ResultSet[] = $Row['C.CourseName'];
      }

      return $ResultSet;
     }

    ...

    $myCourses = getCourses($session[id]);
    foreach ($myCourses as $value)
     {
     print "<br>$value";
     }

or (2) set a flag in getCourses() so that the query is only executed 
once, otherwise returning a result line - something like:

    function getCourses($UID)
     global $link;
     static $result = false;

     if (!$result)
      {
        $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, 
tblusers U,
         tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID =
         $UID", $link );
        if ( ! $result )
         die ( "getRow fatal error: ".mysql_error() );
      }
     {
     return mysql_fetch_array( $result );
     }

    ...

    while ($Row = getCourses($session[id]) as $value)
     {
     print "<br>", $Row['C.CourseName'];
     }

(standard caveats about off-top-of-head, untested code apply)

The reason you are getting the first record TWICE is becaouse of the 
default behaviour of the mysql_fetch_array() function. It returns 
both an associative array - ie, elements of the form <field-name> => 
<value> - and a numerically indexed array (0, 1, 2, etc.). You can 
alter this behaviour by the second parameter of the function: see

        http://www.php.net/manual/en/function.mysql-fetch-array.php

-steve


>I'm hoping someone will spot my dumb mistake.  Thanks very much for any help
>at all on this.
>
>....Brad
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php


-- 
+------------------------------------------------------------------------+
| Steve Edberg                                      [EMAIL PROTECTED] |
| University of California, Davis                          (530)754-9127 |
| Programming/Database/SysAdmin               http://pgfsun.ucdavis.edu/ |
+------------------------------------------------------------------------+
| The end to politics as usual:                                          |
|                 The Monster Raving Loony Party (http://www.omrlp.com/) |
+------------------------------------------------------------------------+
--- End Message ---
--- Begin Message ---
Oops! It's hot, it's Saturday, brain not functioning at 100%, made 
cut'n'paste error:

<SNIP>

or (2) set a flag in getCourses() so that the query is only executed 
once, otherwise returning a result line - something like:

    function getCourses($UID)
     global $link;
     static $result = false;

     if (!$result)
      {
        $result = mysql_query( "SELECT C.CourseName FROM tblcourses C, 
tblusers U,
         tblEnrollment E WHERE C.ID = E.CourseID AND E.UserID = U.ID AND U.ID =
         $UID", $link );
        if ( ! $result )
         die ( "getRow fatal error: ".mysql_error() );
      }
     {
     return mysql_fetch_array( $result );
     }

    ...

    while ($Row = getCourses($session[id]) as $value)
     {
     print "<br>", $Row['C.CourseName'];
     }

<SNIP>

This last block of code should be

    while ($Row = getCourses($session[id]))
     {
     print "<br>", $Row['C.CourseName'];
     }

-steve
-- 
+------------------------------------------------------------------------+
| Steve Edberg                                      [EMAIL PROTECTED] |
| University of California, Davis                          (530)754-9127 |
| Programming/Database/SysAdmin               http://pgfsun.ucdavis.edu/ |
+------------------------------------------------------------------------+
| The end to politics as usual:                                          |
|                 The Monster Raving Loony Party (http://www.omrlp.com/) |
+------------------------------------------------------------------------+
--- End Message ---

Reply via email to