php-general Digest 3 Nov 2003 11:32:09 -0000 Issue 2393

Topics (messages 168358 through 168381):

Re: passing variables to subsequent pages
        168358 by: Chris Shiflett

Re: scalar value as array problem
        168359 by: John W. Holmes

How to run PHP4 and PHP5 side-by-side
        168360 by: Adam Plocher
        168362 by: Comex

Re: recursive acronym - PHP
        168361 by: Lee Doolan

Test.
        168363 by: S. Cole

Re: How to remove a variable from an array
        168364 by: David Otton
        168367 by: David Otton

Image resize with background.
        168365 by: Chris
        168368 by: Martin Towell

applying one function to all array elements
        168366 by: Justin French
        168370 by: Mike Migurski
        168373 by: Chris Shiflett

Extracting random rows
        168369 by: Scott
        168378 by: Marek Kilimajer
        168380 by: Shivanischal

Re: Endless 'while' loops?
        168371 by: Dave G
        168372 by: David Otton
        168377 by: Dave G

Mailing List
        168374 by: PHPLover
        168375 by: Warren Vail

Sleep Function
        168376 by: Glenn Gasner
        168379 by: Marek Kilimajer

Re: Japanese entry into MySQL and into emails
        168381 by: Marek Kilimajer

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 ---
--- Justin French <[EMAIL PROTECTED]> wrote:
> <form action='nextpage.php?manifacturer=<?=$_GET['manufacturer']?>'
> method='get'>

Unless I'm mistaken (which is possible), this won't work. When the
form method is GET, the query string is constructed using the form
fields. Therefore, the manufacturer will be lost.

Hope that helps.

Chris

=====
My Blog
     http://shiflett.org/
HTTP Developer's Handbook
     http://httphandbook.org/
RAMP Training Courses
     http://www.nyphp.org/ramp

--- End Message ---
--- Begin Message --- Steve Turner wrote:

    I have a frustrating problem. I have a shopping cart class that creates
session variable arrays to store the product_id and quantity. My development
machine is running windows 2000 with PHP 4.3.3 and my script is working
perfectly on my machine. When I upload to the remote host running FreeBSD
and PHP 4.3.2 I am getting errors. I believe I am having problems with
assigning the array values, and this is causing other problems. I am using
this statment to assign $_SESSION['cart']['product_id'] with the quantity
using a class with the add_item property.

$cart->add_item($_GET['product_id'], $_GET['quantity']);

I am getting this error.

Warning: Cannot use a scalar value as an array in
/home/designor/public_html/class.php on line 14
Warning: Cannot use a scalar value as an array in
/home/designor/public_html/class.php on line 16

I have no idea what a scalar value even is. I did verify that my form was
passing the values by using
echo $_GET['product_id'] . $_GET['quantity'];

A string or integer would be a scalar value.


What you have is something like this:

$a = 4;
$a[] = 5;

Where you initially make $a an integer, then you try to make it into an array and add an element to it. PHP is giving you a warning (not an error) about this. You may be using any of the array functions on something that's not an array to begin with.

You can either fix the problem, or just adjust your error_reporting() level to not see warnings.

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
Hello, I'm using Apache 2.0 on a Linux box and I'm trying to figure out how to run 
PHP5 (beta2) and PHP4 co-existantly.  I have compiled both of them with 
--enable-versioning, but I can't figure out what I need to put in my httpd.conf to 
make it differentiate the two versions.
 
Ideally I would like php5 to be enabled for certain virtualhosts, and php4 for others. 
 But using .php5 file extensions would be acceptable too.
 
I have compiled PHP4 and PHP5 with the following configure options:
'./configure' '--with-apxs2=/home/httpd/bin/apxs' '--with-mysql=/home/mysql' 
'--enable-track-vars'  '--enable-versioning'
 
Thanks in advance
 
-Adam

--- End Message ---
--- Begin Message ---
<[EMAIL PROTECTED]>
Adam Plocher:
> Hello, I'm using Apache 2.0 on a Linux box and I'm trying to figure
> out how to run PHP5 (beta2) and PHP4 co-existantly.  I have compiled
> both of them with --enable-versioning, but I can't figure out what I
> need to put in my httpd.conf to make it differentiate the two
> versions.
>
> Ideally I would like php5 to be enabled for certain virtualhosts, and
> php4 for others.  But using .php5 file extensions would be acceptable
> too.
>
> I have compiled PHP4 and PHP5 with the following configure options:
> './configure' '--with-apxs2=/home/httpd/bin/apxs'
> '--with-mysql=/home/mysql' '--enable-track-vars'
> '--enable-versioning'
>
> Thanks in advance
>
> -Adam

I have this set up...

LoadModule php5_module "C:/php5/sapi/php4apache2.dll"
ScriptAlias /php/ "C:/php/"
AddType application/x-httpd-php .php5
AddType application/x-httpd-php4 .php
Action application/x-httpd-php4 /php/php.exe

--- End Message ---
--- Begin Message ---
>>>>> "Joachim" == Joachim Krebs <[EMAIL PROTECTED]> writes:

    Joachim> Perhaps it is time to break the record.
    Joachim> Evan Nemerson wrote:
    >> How can you forget the Hurd???

Xinu Is Not Unix

also

MT XINU is UNIX TM backwards

-- 
no toll on the internet; there are paths of many kinds;
whoever passes this portal will travel freely in the world

--- End Message ---
--- Begin Message ---
Disregard. having newsgroup trouble

--- End Message ---
--- Begin Message ---
On Sun, 2 Nov 2003 14:06:31 -0500, you wrote:

>I have an array variable that is set, then put into a session
>variable. All is good so far, but how can I remove a specific variable
>from the array?

unset()

>I have tried basically copying and pasting this, and adding a foreach
>loop. Inside this foreach loop, the array is split apart and I tried
>using unnset, but I couldn't get it to work, so I deleted the code.

unset ($array[$index])

http://uk.php.net/unset

--- End Message ---
--- Begin Message ---
>>I have tried basically copying and pasting this, and adding a foreach
>>loop. Inside this foreach loop, the array is split apart and I tried
>>using unnset, but I couldn't get it to work, so I deleted the code.
>
>unset ($array[$index])
>
>http://uk.php.net/unset

There are examples in the manual, but as you've already tried unset, I guess
I should be explicit:

<?
        $a = array ('a', 'b', 'c', 'd', 'e');

        print_r ($a);

        unset ($a[2]);

        print_r ($a);
?>

--- End Message ---
--- Begin Message ---
Hey guys. I have read a lot of different option to resize images.
 
What about a script that will resize an image, constrain proportions,
and add a background color to whatever is left.
 
For example, I have a picture that is 600 (width) by 300 (height) and I
want to constrain proportions, and resize this to 300 by 400 (width by
height). There would be an extra 250 pixels left in the height, so now
that gets filled in with some background color.
 
This way, the people that have to make any image fit in a certain
location can keep the same aspect ratio, and not have to have an 'out of
place' image.
 
Just a though. What do you guys think?
 
-Chris 
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
try the resize copy function (can't remember the exact name ATM)

Set the destination's first colour to the desired background colour, then
copy/resize the image to it.

Martin

-----Original Message-----
From: Chris [mailto:[EMAIL PROTECTED]
Sent: Monday, 3 November 2003 12:36 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Image resize with background.


Hey guys. I have read a lot of different option to resize images.
 
What about a script that will resize an image, constrain proportions,
and add a background color to whatever is left.
 
For example, I have a picture that is 600 (width) by 300 (height) and I
want to constrain proportions, and resize this to 300 by 400 (width by
height). There would be an extra 250 pixels left in the height, so now
that gets filled in with some background color.
 
This way, the people that have to make any image fit in a certain
location can keep the same aspect ratio, and not have to have an 'out of
place' image.
 
Just a though. What do you guys think?
 
-Chris 
[EMAIL PROTECTED]

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

Can someone show me a simple, clean way to apply one function (eg stripslashes()) to every element in an array (eg $_POST)?

I've been doing it with a foreach() loop, but there has to be a better way. I've also seen http://www.php.net/array_walk, but couldn't determine how/if it suited my needs.


TIA Justin

--- End Message ---
--- Begin Message ---
>Can someone show me a simple, clean way to apply one function (eg
>stripslashes()) to every element in an array (eg $_POST)?
>
>I've been doing it with a foreach() loop, but there has to be a better
>way.  I've also seen http://www.php.net/array_walk, but couldn't
>determine how/if it suited my needs.

What part of "Apply a user function to every member of an array" makes it
difficult to assess array_walk's usefulness? If it helps, array_map
("Applies the callback to the elements of the given arrays") does
something similar.

---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca            http://mike.teczno.com/contact.html

--- End Message ---
--- Begin Message ---
--- Justin French <[EMAIL PROTECTED]> wrote:
> Can someone show me a simple, clean way to apply one function (eg 
> stripslashes()) to every element in an array (eg $_POST)?
[snip]
> I've also seen http://www.php.net/array_walk, but couldn't 
> determine how/if it suited my needs.

Maybe you can explain how your need is not met with array_walk()?
That would be my suggestion, since it seems to do exactly what you
want, but then you mention that you have already looked at it.

It does require that the function take two parameters, which isn't
the case with stripslashes(). So, you can make a very tiny wrapper
function that discards the second parameter (since you don't need
it):

<?
function array_stripslashes(&$var, $key)
{
     $var = stripslashes($var);
}
                                                                     
                                                                     

array_walk($_POST, 'array_stripslashes');
?>

Hope that helps.

Chris

=====
My Blog
     http://shiflett.org/
HTTP Developer's Handbook
     http://httphandbook.org/
RAMP Training Courses
     http://www.nyphp.org/ramp

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

Below is a boiled-down example of the problem I'm having.  I'm trying to
extract rows randomly from MySql, but I keep getting the same one. It
works if I query MySql directly from the command line, so it seems like
a php problem.

Thanks,
Scott

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
  <meta name="GENERATOR" content="Quanta Plus">
</head>
<body>

<?

include ("connectlpi.php");

$sql = "
select id
from $table_name
order by rand()
limit 1
";

$result = @mysql_query($sql,$connection) or die("Couldn't execute
query.");

while ($row = mysql_fetch_array($result)) {

$id = $row['id'];

}

echo "$id";

?>



</body>
</html>

--- End Message ---
--- Begin Message --- Hello, works for me. As a workaround you can pass a random integer to te RAND() function to be used as seed value.

Scott wrote:
Hello,

Below is a boiled-down example of the problem I'm having.  I'm trying to
extract rows randomly from MySql, but I keep getting the same one. It
works if I query MySql directly from the command line, so it seems like
a php problem.

Thanks,
Scott

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
  <meta name="GENERATOR" content="Quanta Plus">
</head>
<body>

<?

include ("connectlpi.php");

$sql = "
select id
from $table_name
order by rand()
limit 1
";

$result = @mysql_query($sql,$connection) or die("Couldn't execute
query.");

while ($row = mysql_fetch_array($result)) {

$id = $row['id'];

}

echo "$id";

?>



</body>
</html>


--- End Message ---
--- Begin Message ---
hi,

do try this - "select * from my_table orer by rand() limit my_max_rows" like
"select * from questions order by rand() limit 5". works for me. i'm
surprised too. but if u still want to do it in PHP, do go ahead.

warm regards,
-shiva


"Scott" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> Below is a boiled-down example of the problem I'm having.  I'm trying to
> extract rows randomly from MySql, but I keep getting the same one. It
> works if I query MySql directly from the command line, so it seems like
> a php problem.
>
> Thanks,
> Scott
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
> <html>
> <head>
>   <title></title>
>   <meta http-equiv="Content-Type" content="text/html;
> charset=iso-8859-1">
>   <meta name="GENERATOR" content="Quanta Plus">
> </head>
> <body>
>
> <?
>
> include ("connectlpi.php");
>
> $sql = "
> select id
> from $table_name
> order by rand()
> limit 1
> ";
>
> $result = @mysql_query($sql,$connection) or die("Couldn't execute
> query.");
>
> while ($row = mysql_fetch_array($result)) {
>
> $id = $row['id'];
>
> }
>
> echo "$id";
>
> ?>
>
>
>
> </body>
> </html>

--- End Message ---
--- Begin Message ---
Thank you Lief, Hanuska and Jay for your comments and advice.

> (it automagically knows which result it's on)

        This was the piece of information that I was missing. I did not
know PHP had any "automagic" in it's handling of arrays.
        However, now that I think I know what's going on, my code still
does not seem to be working. When I execute the following, I get a parse
error on the line where my first square brackets (...for " .member[1];)
appears. If I take the square brackets out, the code parses, but does
not do anything.
        Here is the problematic code:
db_connect();
$query = "select * from tablename where active = 1";
$result = mysql_query($query);
while ($member = mysql_fetch_row($result));
{
$subject = "EigoImprov Newsletter for " .member[1];
$mailcontent = "Dear " .$member[0] .",\n".$message ."\nThis message was
sent to [2]" .$member;
mail($member[2], $subject, $mailcontent, $fromaddress);
}
        Why is this not parsing?

-- 
Cheers!
Dave G
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
On Mon, 3 Nov 2003 12:29:10 +0900, you wrote:

Without running the code, I can see two immediate problems.

>$subject = "EigoImprov Newsletter for " .member[1];

should be

$subject = "EigoImprov Newsletter for " . $member[1];

Also rewrite

>$mailcontent = "Dear " .$member[0] .",\n".$message ."\nThis message was
>sent to [2]" .$member;

as something closer to

$mailcontent = "Dear {$member[0]},\n$message\nThis message was
sent to {$member[2]}";

There are a couple of other good-practice changes you could make:

List the columns explicitly - that way your code will still work if the
database structure gets changed:

>$query = "select * from tablename where active = 1";

$query = "SELECT col1, col2, col3 FROM tablename WHERE active = 1";

>$result = mysql_query($query);

Check for failure after doing the query.

$result = mysql_query ($query);
if ($result == FALSE)
{
        die ("Query error");
}

--- End Message ---
--- Begin Message ---
GoLive Gurus,

        The problem has been resolved. I now understand much better how
"while" loops operate, and fixed the problem of the script not parsing.
I am now successfully making mailing lists using PHP.
        While I was banging my head thinking there was something wrong
with how I was accessing the array variable, it turned out to be the
most simple thing. I had mistakenly placed a semi-colon at the end of my
while() command, and that was the root of my troubles. It never ceases
to amaze me how finding that one errant punctuation mark can be so
difficult and misleading!
        In any case, I very appreciative of the many valuable tips
offered, and I believe tightening up the code as suggested by people on
this list helped me see my script better and isolate the problem.
        Many thanks to David, Jay, Hanuska, Leif, and Teren for their
comments!

-- 
Cheers!
Dave G
[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---
Dear All,

I would like to setup a mailing list for my company.
I have a database containing email address of my clients along with other
details.
How can I send them mails ?
If i write a script containing the mail function and loop the address, I
think that might generate a script timeout error. I feel increasing the
script timeout is not a good solution. I would like to know how you manage
such situations. I feel this is a common problem but i didnt find any
solution on the net. Do I need to use any sw or are there any already
available scripts.

Thanks a Lot !!
Long Live PHP !!

Thanks & Regards, 
___________________________ 
PHPLover
"Göd döësn't pläy dícë." 
- Älbërt Ëínstëín



--- End Message ---
--- Begin Message ---
Allowing scripts to run without some kind of time limit may not be prudent,
but settling for the timelimit imposed on online web pages is not reasonable
either.  I would recommend you reset the time limit to something reasonable
to perform your email tasks on the computer you have available.

http://www.php.net/manual/en/function.set-time-limit.php

As long as you don't have a "run away" program, I can't think of any reason
not to allow it to have the time it needs to get the job done.

Warren Vail
[EMAIL PROTECTED]


-----Original Message-----
From: PHPLover [mailto:[EMAIL PROTECTED]
Sent: Sunday, November 02, 2003 10:18 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Mailing List


Dear All,

I would like to setup a mailing list for my company.
I have a database containing email address of my clients along with other
details.
How can I send them mails ?
If i write a script containing the mail function and loop the address, I
think that might generate a script timeout error. I feel increasing the
script timeout is not a good solution. I would like to know how you manage
such situations. I feel this is a common problem but i didnt find any
solution on the net. Do I need to use any sw or are there any already
available scripts.

Thanks a Lot !!
Long Live PHP !!

Thanks & Regards,
___________________________
PHPLover
"Göd döësn't pläy dícë."
- Älbërt Ëínstëín

--- End Message ---
--- Begin Message ---
The php.net documentation for the sleep and usleep functions has me
confused.  I'm using shared hosting and I need to email my whole mailing
list while not clogging the shared mail server.  What I'm trying to do is
put a pause between each email sent (like 10 seconds) so I can set it up to
send a thousand (or whatever) messages without manually putting time between
batches.  My guess is that I should put a line with sleep(10); inside the
mail sending loop so that it pauses between notes.  However, the Jan-17 note
on the usleep function mentions that these kinds of loops can consume 100%
of CPU while running.  The Jan-29 note on the time() function says that
sleep uses way less CPU than wait(). I don't know how to test CPU usage of
any PHP function.  Is sleep() really so CPU intensive that I should avoid
it, is there a better function to use, or is it exactly what I need and
it'll be no problem even on a shared server?

Thanks!
Glenn Gasner
glenn at perex dot com

--- End Message ---
--- Begin Message --- It is exactly what you need. And you can lower the sleep time, I think 1 or 2 seconds are just enough.

Glenn Gasner wrote:
The php.net documentation for the sleep and usleep functions has me
confused.  I'm using shared hosting and I need to email my whole mailing
list while not clogging the shared mail server.  What I'm trying to do is
put a pause between each email sent (like 10 seconds) so I can set it up to
send a thousand (or whatever) messages without manually putting time between
batches.  My guess is that I should put a line with sleep(10); inside the
mail sending loop so that it pauses between notes.  However, the Jan-17 note
on the usleep function mentions that these kinds of loops can consume 100%
of CPU while running.  The Jan-29 note on the time() function says that
sleep uses way less CPU than wait(). I don't know how to test CPU usage of
any PHP function.  Is sleep() really so CPU intensive that I should avoid
it, is there a better function to use, or is it exactly what I need and
it'll be no problem even on a shared server?

Thanks!
Glenn Gasner
glenn at perex dot com


--- End Message ---
--- Begin Message --- I have only one advise for you: send yourself an email with the kanji encoding and check the email headers with the headers you set.

Dave G wrote:

        Thank you Edwin, Marek, and Eugene for your responses and
advice.
        For storing the Japanese names in kanji in the database, I've
changed the column to "blob". Storing and retrieving the fields seems to
work okay in all my tests, and this solution seemed to be the easiest
and without any potential impact on the rest of the database. Thank you
for this solution.
        For sending the email in Japanese, I am still not quite getting
it. At first I attempted to attach character set information within the
mail() command like so:
$addheaders = 'From: ' .$email .'\r\nContent-Type: text/html;
charset=iso-2022-jp';
mail ($toaddress, $subject, $mailcontent, $addheaders);
        This sends the mail correctly, but the content is still coming
out as ASCII gibberish.
        I then attempted to use the mb_send_mail() command, like so
(this time a "From: " address being the only additional header:
mb_language(Japanese);
mb_send_mail($toaddress, $subject, $mailcontent, $fromaddress);
        But this had exactly the same result.
        I see on the
http://jp2.php.net/manual/en/function.mb-send-mail.php web page there is
lots of additional comments on the use of mb-send-mail(), but the
technical vocabulary is beyond me.
        Can someone help me tweak this code to successfully send a kanji
email?


--- End Message ---

Reply via email to