OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
php-general Digest 10 Jan 2006 23:59:38 -0000 Issue 3898

php-general-digest-helplists.php.net
Date: Tue Jan 10 2006 - 17:59:38 CST


php-general Digest 10 Jan 2006 23:59:38 -0000 Issue 3898

Topics (messages 228393 through 228444):

Re: PHP5, Soap, WSDL, and unbounded xsd:choice types.
        228393 by: Rob

Re: Browser on server doesn't refresh
        228394 by: Albert

Sending mail with php-
        228395 by: Dotan Cohen
        228396 by: Albert
        228398 by: Sameer N Ingole
        228403 by: Dotan Cohen
        228404 by: Albert
        228405 by: Sameer N Ingole
        228439 by: Dotan Cohen

php + mysql - timstamp - calculate hours remaining
        228397 by: Gregory Machin
        228399 by: David Grant
        228400 by: Albert
        228401 by: Albert
        228402 by: David Grant
        228406 by: M. Sokolewicz

Re: Warning: Missing argument 7 calling a function
        228407 by: Ford, Mike

Is there a way to display data from database for Select Options in a form?
        228408 by: Sue
        228409 by: Adrian Bruce
        228410 by: David Grant
        228411 by: Jochem Maas
        228412 by: Jochem Maas
        228414 by: Jay Blanchard
        228415 by: David Grant
        228418 by: Jochem Maas
        228419 by: Jay Blanchard
        228421 by: Adrian Bruce
        228423 by: Jay Paulson \(CE CEN\)
        228424 by: Jochem Maas
        228425 by: David Grant
        228426 by: Jochem Maas
        228427 by: Jochem Maas
        228428 by: DarkX
        228431 by: Jochem Maas
        228437 by: Mike Smith
        228440 by: Jake Gardner

Re: Floating numbers truncating to two digits without rounding
        228413 by: Mark Steudel
        228442 by: Gerry Danen

Re: Image editing?
        228416 by: Raj Shekhar

replacing .shtml #exec cgi with php calls
        228417 by: The Doctor
        228420 by: Jay Blanchard
        228422 by: David Grant
        228430 by: The Doctor
        228432 by: John Nichel

SOAP Problems.
        228429 by: Jay Paulson \(CE CEN\)

Re: SOAP Problems SOLVED!
        228433 by: Jay Paulson \(CE CEN\)

[QF] I would like to change the javascript validation function
        228434 by: Mark Steudel
        228435 by: Mark Steudel

problem with large arrays in php 4.3.2
        228436 by: Jesse Guardiani
        228438 by: Jesse Guardiani

Re: problem with currency signs
        228441 by: Satyam

Re: PHP and SOAP newbie questions
        228443 by: Angelo Zanetti

PHP CGI Variables
        228444 by: Tim Traver

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscribelists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscribelists.php.net

To post to the list, e-mail:
        php-generallists.php.net

----------------------------------------------------------------------

attached mail follows:


Simon Detheridge wrote:
<snip />

>
> What I want PHP to do, is enable me to access my 'bar' and 'baz'
> elements in the order in which they appear in the document, instead of
> having it glob them together for each type. However, I am unable to
> modify the output of the webservice itself as it interoperates nicely
> with other things already.
>
> Can I get There from Here with PHP's own SoapClient, or do I have to
> parse the xml by hand?

I don't see how you could do it without altering the WSDL, which would
alter the SOAP response. Your best bet if that is out of the question is
to parse the portion of the response you need manually. You also need to
be sure that the server is always going to send those elements in the
exact order you are expecting.

Rob

attached mail follows:


Mike Tuller wrote:
> locally, everything works. When I put the script on my OS X Server
> and run the script, and click on the link to go back, the information
> is not updated. I have to refresh the page.

> PHP 5.04 on my laptop and 4.3.11 on the server. Is there some setting
> in Apache that would cause the page not to refresh?

It sounds to me that there is a caching problem somewhere.

Try adding the following to the top of the page:
<?
  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  header("Cache-Control: no-store, no-cache, must-revalidate");
  header("Cache-Control: post-check=0, pre-check=0", false);
  header("Cache-Control: private");
  header("Pragma: no-cache");
?>

It will tell any caching server and/or browser not to cache the page

Albert
PS List replies only please!

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 2006/01/09
 

attached mail follows:


On my home Fedora Core 4 box I run Apache 2.0. Sometimes when sending
mail with php no mail is delivered, and I find this in the logs:

<<< 550-Verification failed for <apachelocalhost.localdomain>
<<< 550-unrouteable mail domain "localhost.localdomain"
<<< 550 Sender verify failed

So I changed the only email address in httpd.conf to:
ServerAdmin dotanlyricslist.com

But I still get the error! I did restart apache and even went so far as to
reboot the machine. If I cannot modify the parameter within apache,
then where should I modify it? Within php? Within sendmail?

Thank you.

Dotan Cohen
http://technology-sleuth.com/question/what_are_the_advantages_of_lcd_monitors.html
(-)

attached mail follows:


Dotan Cohen wrote:
> But I still get the error! I did restart apache and even went so far as to
> reboot the machine. If I cannot modify the parameter within apache,
> then where should I modify it? Within php? Within sendmail?

Look for the "sendmail_from" parameter in the "mail function" section of
php.ini.

Or define the additional parameters:

[quote from PHP documentation]
bool mail ( string to, string subject, string message [, string
additional_headers [, string additional_parameters]] )
[/quote]

[quote from Example 486. Sending mail with extra headers and setting an
additional command line parameter. In PHP documentation]
<?php
mail("nobodyexample.com", "the subject", $message,
    "From: webmaster{$_SERVER['SERVER_NAME']}",
"-fwebmaster{$_SERVER['SERVER_NAME']}");
?>
[/quote]

HTH

Albert
PS List replies only please!

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 2006/01/09
 

attached mail follows:


Dear Dotan,
Dotan Cohen wrote:

>On my home Fedora Core 4 box I run Apache 2.0. Sometimes when sending
>mail with php no mail is delivered, and I find this in the logs:
>
><<< 550-Verification failed for <apachelocalhost.localdomain>
><<< 550-unrouteable mail domain "localhost.localdomain"
><<< 550 Sender verify failed
>
You are getting this error because apachelocalhost.localdomain cannot
be reached from Internet and whoever you are sending mail to may have
something called sender check. This verifies if the sender of this mail
is reachable. This avoids spammers to send mails using unreachable
addresses. Also he may be checking spf-record for your From: domain on
mail envelop.

>
>So I changed the only email address in httpd.conf to:
>ServerAdmin dotanlyricslist.com
>
What error you are getting after you change address in apache and try
sending mail after restarting apache?

>
>But I still get the error! I did restart apache and even went so far as to
>reboot the machine. If I cannot modify the parameter within apache,
>then where should I modify it? Within php? Within sendmail?
>

--
Sameer N. Ingole
Blog: http://weblogic.noroot.org/

attached mail follows:


On 1/10/06, Albert <albertfastworx.com> wrote:
> Dotan Cohen wrote:
> > But I still get the error! I did restart apache and even went so far as to
> > reboot the machine. If I cannot modify the parameter within apache,
> > then where should I modify it? Within php? Within sendmail?
>
> Look for the "sendmail_from" parameter in the "mail function" section of
> php.ini.
>
> Or define the additional parameters:
>
> [quote from PHP documentation]
> bool mail ( string to, string subject, string message [, string
> additional_headers [, string additional_parameters]] )
> [/quote]
>
> [quote from Example 486. Sending mail with extra headers and setting an
> additional command line parameter. In PHP documentation]
> <?php
> mail("nobodyexample.com", "the subject", $message,
> "From: webmaster{$_SERVER['SERVER_NAME']}",
> "-fwebmaster{$_SERVER['SERVER_NAME']}");
> ?>
> [/quote]
>
> HTH
>
> Albert
> PS List replies only please!

That most certainly is how I do it- just like TFM says! Actually, the
last field is a variable that is defined earlier, but I have outputed
it's contents to the screen to verify that it contains what it should.

Dotan Cohen
http://technology-sleuth.com/long_answer/what_is_a_cellphone.html
(*)

attached mail follows:


Dotan Cohen wrote:
> That most certainly is how I do it- just like TFM says! Actually, the
> last field is a variable that is defined earlier, but I have outputed
> it's contents to the screen to verify that it contains what it should.

Have a look at PHPMailer (http://www.phpclasses.org/browse/package/264.html)

It has made my life a lot easier.

Albert

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 2006/01/09
 

attached mail follows:


Dear Dotan,

You know cross-posting is bad..?

replies-lists-phplistmail.innovate.net wrote:

>
>
>he also sent a message to the fedora list where he's been responded
>to.
>
>
>
>------------ Original Message ------------
>
>>Date: Tuesday, January 10, 2006 07:03:17 PM +0530
>>From: Sameer N Ingole <strikeproscrutiny.com>
>>To: php-generallists.php.net
>>Subject: Re: [PHP] Sending mail with php-
>>
>>Dear Dotan,
>>Dotan Cohen wrote:
>>
>>
>>>On my home Fedora Core 4 box I run Apache 2.0. Sometimes when
>>>sending mail with php no mail is delivered, and I find this in the
>>>logs:
>>>
>>><<< 550-Verification failed for <apachelocalhost.localdomain>
>>><<< 550-unrouteable mail domain "localhost.localdomain"
>>><<< 550 Sender verify failed
>>>
>>>
>>You are getting this error because apachelocalhost.localdomain
>>cannot be reached from Internet and whoever you are sending mail to
>>may have something called sender check. This verifies if the sender
>>of this mail is reachable. This avoids spammers to send mails using
>>unreachable addresses. Also he may be checking spf-record for your
>>From: domain on mail envelop.
>>
>>
>>>So I changed the only email address in httpd.conf to:
>>>ServerAdmin dotanlyricslist.com
>>>
>>>
>>What error you are getting after you change address in apache and
>>try sending mail after restarting apache?
>>
>>
>>>But I still get the error! I did restart apache and even went so
>>>far as to reboot the machine. If I cannot modify the parameter
>>>within apache, then where should I modify it? Within php? Within
>>>sendmail?
>>>
>>>
>>--
>>Sameer N. Ingole
>>Blog: http://weblogic.noroot.org/
>>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>---------- End Original Message ----------
>
>
>
>

--
Sameer N. Ingole
Blog: http://weblogic.noroot.org/

attached mail follows:


On 1/10/06, Sameer N Ingole <strikeproscrutiny.com> wrote:
> Dear Dotan,
>
> You know cross-posting is bad..?
>
> replies-lists-phplistmail.innovate.net wrote:
>
> >
> >
> >he also sent a message to the fedora list where he's been responded
> >to.
> >
> >
> >
> >------------ Original Message ------------
> >
> >>Date: Tuesday, January 10, 2006 07:03:17 PM +0530
> >>From: Sameer N Ingole <strikeproscrutiny.com>
> >>To: php-generallists.php.net
> >>Subject: Re: [PHP] Sending mail with php-
> >>
> >>Dear Dotan,
> >>Dotan Cohen wrote:
> >>
> >>
> >>>On my home Fedora Core 4 box I run Apache 2.0. Sometimes when
> >>>sending mail with php no mail is delivered, and I find this in the
> >>>logs:
> >>>
> >>><<< 550-Verification failed for <apachelocalhost.localdomain>
> >>><<< 550-unrouteable mail domain "localhost.localdomain"
> >>><<< 550 Sender verify failed
> >>>
> >>>
> >>You are getting this error because apachelocalhost.localdomain
> >>cannot be reached from Internet and whoever you are sending mail to
> >>may have something called sender check. This verifies if the sender
> >>of this mail is reachable. This avoids spammers to send mails using
> >>unreachable addresses. Also he may be checking spf-record for your
> >>From: domain on mail envelop.
> >>
> >>
> >>>So I changed the only email address in httpd.conf to:
> >>>ServerAdmin dotanlyricslist.com
> >>>
> >>>
> >>What error you are getting after you change address in apache and
> >>try sending mail after restarting apache?
> >>
> >>
> >>>But I still get the error! I did restart apache and even went so
> >>>far as to reboot the machine. If I cannot modify the parameter
> >>>within apache, then where should I modify it? Within php? Within
> >>>sendmail?
> >>>
> >>>
> >>--
> >>Sameer N. Ingole
> >>Blog: http://weblogic.noroot.org/
> >>
> >>--
> >>PHP General Mailing List (http://www.php.net/)
> >>To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >
> >---------- End Original Message ----------
> >

Yes, I know that cross-posting is unencouraged behaviour. However, I
really thought that apache-users was the place to ask. When I received
no reply from the apache mailing list, I did not know whether to ask
here or at my distro's (Fedora) list. As the problem is in a php
script, however, it involves php AND apache AND sendmail, all of which
were installed by default on my distro- and are expected to work. I
was not sure if the fault is with me (my misconfiguration) or with the
distro (distros default configuration).

So I appologize, and here I learned yet another lesson- when I _do_
cheat- I get caught!

Dotan Cohen
http://technology-sleuth.com/short_answer/what_is_hdtv.html
(&^

attached mail follows:


Hi
Please could you advise.

I have a table with a timestamp column and would like to use his to
calculate the age of the record . how would i go about this...
I would also like to exicute a mysql stament that pasess the tables and
removes fields older than say 72 hours. how would i go about this . ?

many thanks
--
Gregory Machin
greglinuxpro.co.za
gregory.machingmail.com
www.linuxpro.co.za
www.exponent.co.za
Web Hosting Solutions
Scalable Linux Solutions
www.iberry.info (support and admin)

+27 72 524 8096

attached mail follows:


Gregory,

Gregory Machin wrote:
> I have a table with a timestamp column and would like to use his to
> calculate the age of the record . how would i go about this...
> I would also like to exicute a mysql stament that pasess the tables and
> removes fields older than say 72 hours. how would i go about this . ?

A timestamp is the time in seconds (since Jan 1 1970), so you can
ascertain the age in seconds by subtracting the stored timestamp from
the current timestamp.

You can find the current timestamp in MySQL using the
CURRENT_TIMESTAMP() function.

Once you have the age of the record, finding 72 hours is fairly trivial
- 72 hours is 259200 seconds (72hrs * 60mins * 60secs).

Therefore your query will be:

DELETE FROM <TABLE> WHERE CURRENT_TIMESTAMP() - <FIELD> > 259200

David
--
David Grant
http://www.grant.org.uk/

attached mail follows:


Gregory Machin wrote:
> I have a table with a timestamp column and would like to use his to
> calculate the age of the record . how would i go about this...

Convert your timestamp to a unix timestamp (see mktime() function).

Use the value returned by time() to calculate the difference in seconds.

$age = time() - $tableTimestamp;

Divide by 3600 to get hours

> I would also like to exicute a mysql stament that pasess the tables and
> removes fields older than say 72 hours. how would i go about this . ?

Get a timestamp of 72 hours ago:

$olderThan72Hours = time() - (72 * 3600);

Convert to the same format as your timestamp column:

$timestamp = date('Y-m-d H:i:s', $olderThan72Hours);

Delete the records from the table:
mysql_query("DELETE FROM table WHERE timestamp >= '$timestamp'") or
die('Could not delete from table');

HTH

Albert

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 2006/01/09
 

attached mail follows:


I wrote:
> Delete the records from the table:
> mysql_query("DELETE FROM table WHERE timestamp >= '$timestamp'") or
> die('Could not delete from table');

That query should be

DELETE FROM table WHERE timestamp <= '$timestamp'

Sorry about that.

Albert

--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.14.16/225 - Release Date: 2006/01/09
 

attached mail follows:


Gregory,

David Grant wrote:
> Gregory Machin wrote:
>> I have a table with a timestamp column and would like to use his to
>> calculate the age of the record . how would i go about this...
>> I would also like to exicute a mysql stament that pasess the tables and
>> removes fields older than say 72 hours. how would i go about this . ?
>
> A timestamp is the time in seconds (since Jan 1 1970), so you can
> ascertain the age in seconds by subtracting the stored timestamp from
> the current timestamp.
>
> You can find the current timestamp in MySQL using the
> CURRENT_TIMESTAMP() function.
>
> Once you have the age of the record, finding 72 hours is fairly trivial
> - 72 hours is 259200 seconds (72hrs * 60mins * 60secs).
>
> Therefore your query will be:
>
> DELETE FROM <TABLE> WHERE CURRENT_TIMESTAMP() - <FIELD> > 259200

Following Albert's reply, the query ought to read:

DELETE FROM <TABLE> WHERE CURRENT_TIMESTAMP() - UNIX_TIMESTAMP(<FIELD> >
259200

David
--
David Grant
http://www.grant.org.uk/

attached mail follows:


David Grant wrote:
> Gregory,
>
> David Grant wrote:
>
>>Gregory Machin wrote:
>>
>>>I have a table with a timestamp column and would like to use his to
>>>calculate the age of the record . how would i go about this...
>>>I would also like to exicute a mysql stament that pasess the tables and
>>>removes fields older than say 72 hours. how would i go about this . ?
>>
>>A timestamp is the time in seconds (since Jan 1 1970), so you can
>>ascertain the age in seconds by subtracting the stored timestamp from
>>the current timestamp.
>>
>>You can find the current timestamp in MySQL using the
>>CURRENT_TIMESTAMP() function.
>>
>>Once you have the age of the record, finding 72 hours is fairly trivial
>>- 72 hours is 259200 seconds (72hrs * 60mins * 60secs).
>>
>>Therefore your query will be:
>>
>>DELETE FROM <TABLE> WHERE CURRENT_TIMESTAMP() - <FIELD> > 259200
>
>
> Following Albert's reply, the query ought to read:
>
> DELETE FROM <TABLE> WHERE CURRENT_TIMESTAMP() - UNIX_TIMESTAMP(<FIELD> >
> 259200
>
> David
David, your solution is correct (though you made a typo; it should read:
"DELETE FROM <TABLE> WHERE CURRENT_TIMESTAMP() - UNIX_TIMESTAMP(<FIELD>)
> 259200"), though slow because mysql needs to calculate a timestamp,
based on all the times/dates stored. Now, all these methods depend on
how the OP stored the dates in his database. In general, there are 2
ways which are used most often:
1 - As a UNIX timestamp (as per Albert's example), or
2 - As a MySQL-timestamp (as per ISO 8601; YYYY-MM-DD)

If the OP uses #1 to store the date, the easiest way is to do a
modification of David's solution, and do:
"DELETE FROM <TABLE> WHERE <field> < UNIX_TIMESTAMP(NOW())-259200", this
is a quick solution, because all MySQL now needs to do is compare an
integer to an integer for each row (which is pretty fast).
If the OP uses #2, then it's easier to use MySQL's built-in functions
for date-comparison. It's actually faster than converting the dates to
UNIX timestamps and comparing them as per #1, so let's do that. To
achieve this, you can use mysql's own date functions:
"DELETE FROM <TABLE> WHERE <field> < NOW()- INTERVAL 72 HOUR"

hope this short discussion helped,
- tul

attached mail follows:


On 09 January 2006 16:14, enediel gonzalez wrote:

> thanks everybody who answered me,
> the segment bellow is the code that gave me problems, the $app_name
> was the 7th parameter neccesary for me to call the
> GetCommandDeclaration function,
> the solution I had for a while was to declare the variable global. :(

Um -- the code you have posted contains a declaration for function
GetCommandDeclaration(), but no call of it -- only one to
GetProcedureDeclaration().

And in answer to you original question, you could always make the 7th
parameter optional:

    function GetCommandDeclaration($RPM, $var2, $RFactor,
                                   $minimum, $maximum, $sport,
                                   $app_name='default') {

>
> $app_name = "";
>
> function GetCommandDeclaration($RPM, $var2, $RFactor, $minimum,
> $maximum, $sport){
> global $app_name;
> //code here
> }
>
> function Process(){
> global $db, $app_name;
> $query = get_query_declaration();
>
> $result = mysql_query($query, $db);
> $rowCount = mysql_num_rows($result);
> $myCounter = 0;
>
> while ($myCounter < $rowCount){
> mysql_data_seek($result, $myCounter);
> $row = mysql_fetch_assoc($result);
>
> $RPM = $row['RPM'];
> $var2 = $row['var2'];
> $RFactor = $row['RFactor'];
> $minimum = $row['minimum'];
> $maximum = $row['maximum'];
> $sport = $row['$sport'];
>
> $app_name = $row['app_name'];
>
> $str_command_declaration = GetProcedureDeclaration($RPM, $var2,
> $RFactor,
>
> $minimum, $maximum,
> $sport);
> //code here
> }
> }
> Linux user 300141
> Debian GNU/Linux

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS, LS6 3QS, United Kingdom
Email: m.fordleedsmet.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

attached mail follows:


Hello,

We have a form that contains a Select option for a listing of available
dates for the user to choose from. Right now we have to manually change the
dates within the form's Selection list as new dates become available to
choose from. We currently store these available dates in our database, and
am wondering if we can somehow extract these dates from the table to display
in our form? This would eliminate alot of maintenance needed to this form.
If anyone has any ideas as to reference material etc. that I may look which
would give me an idea how to do this using PHP, I'd appreciate it!

Thanks!
Sue

attached mail follows:


Something along these lines will work fine

<?php
$query = mysql_query("select dates from table ") or die (mysql_error());

echo"<select name='test'>";

while ($row = mysql_fetch_array($query, MYSQL_NUM)){
   
    echo"<option value='$row[0]'>$row[1]</option>";

}
echo"</select>";
?>

Regards
Ade

Sue wrote:

>Hello,
>
>We have a form that contains a Select option for a listing of available
>dates for the user to choose from. Right now we have to manually change the
>dates within the form's Selection list as new dates become available to
>choose from. We currently store these available dates in our database, and
>am wondering if we can somehow extract these dates from the table to display
>in our form? This would eliminate alot of maintenance needed to this form.
>If anyone has any ideas as to reference material etc. that I may look which
>would give me an idea how to do this using PHP, I'd appreciate it!
>
>Thanks!
>Sue
>
>
>

attached mail follows:


Sue,

Sue wrote:
> We have a form that contains a Select option for a listing of available
> dates for the user to choose from. Right now we have to manually change the
> dates within the form's Selection list as new dates become available to
> choose from. We currently store these available dates in our database, and
> am wondering if we can somehow extract these dates from the table to display
> in our form? This would eliminate alot of maintenance needed to this form.
> If anyone has any ideas as to reference material etc. that I may look which
> would give me an idea how to do this using PHP, I'd appreciate it!

I'd recommend reading the PHP manual at:

http://www.php.net/docs.php

There you will find chapters on using various database functions, such as:

MySQL
http://www.php.net/manual/en/ref.mysql.php

PostgreSQL
http://www.php.net/manual/en/ref.pgsql.php

Microsoft SQL Server
http://www.php.net/manual/en/ref.mssql.php

Oracle
http://www.php.net/manual/en/ref.oracle.php

David
--
David Grant
http://www.grant.org.uk/

attached mail follows:


Sue wrote:
> Hello,
>
> We have a form that contains a Select option for a listing of available
> dates for the user to choose from. Right now we have to manually change the
> dates within the form's Selection list as new dates become available to
> choose from. We currently store these available dates in our database, and
> am wondering if we can somehow extract these dates from the table to display
> in our form? This would eliminate alot of maintenance needed to this form.
> If anyone has any ideas as to reference material etc. that I may look which
> would give me an idea how to do this using PHP, I'd appreciate it!

I am guessing that your php skills are not that hot. filling a select box
is php 101.... here is function that generates a selectbox based on the given
'data' - now you have to go and figure out how to build the array $items
(which is passed as the first arg to this function) from the data in your table:

/** selectTag()
  * generate an html select list using the given $items as options.
  *
  * param array $items - list of items to display as options
  * param array $selected - value of select item in $items
  * param string $selectname - value of select tag's name attribute
  * param numeric $addnone - add a 'blank' option to the top of the list
  * (different types depending on valuepassed)
  * param string $onchange - value of select tag's onchange attribute
  * param string $selectid - value of select tag's id attribute
  * param boolean $readonly - whether the select tag is readsonly or not
  * param array $readonly - whether the select tag is readsonly or not
  * param boolean $option_class_arr - optional CSS class names for individual option tags
  * param string $selectHTMLattribs - passthru HTML (attributes for the select tag)
  *
  * return string
  */
function selectTag($items, $selected = '', $selectname = '',
                   $addnone = 0, $onchange = '', $selectid = '',
                   $readonly = 0, $option_class_arr = array(), $selectHTMLattribs = '')
{
     // must have an array of items
     if (!is_array($items)) {
         return '';
     }

     // determine the value of the selected item
     $selected = strtolower(trim($selected));

     // list of options we will generate
     $opts = array();

     // add item with value 0 ?
     $add_none_value = 0;
     switch ( $addnone ) {
         case '1': // item display = 'none'
             $zero_id_item = getStr('None');
             break;
         case '3': // item display = '0'
             $zero_id_item = getStr('zero_digit');
             break;
         case '2': // item display = 'all'
         case '4': // item display = 'all <digit>' e.g. 'all 3'
             $zero_id_item = getStr('All');
             break;
         default:
             if(!empty($addnone) && $addnone != '0') {
                 if(is_array($addnone)) {
                     list($add_none_value, $zero_id_item) = each($addnone);
                 } else {
                     // here we can drop in a custom 'blank' item:
                     $zero_id_item = $addnone;
                 }
             }
             break;
     }
     if (isset($zero_id_item)) {
         $thisselected = ($selected > '') ? '' : ' selected="selected"';
         // FIX THE NEXT LINE - BUT NOT IMPORTANT
         $opts[] = '<option value="'.htmlentities($add_none_value, ENT_QUOTES).'"'
                      .$thisselected'>'.ucwords($zero_id_item).'</option>';
     }

     $thisselected = '';
     foreach ($items as $value => $displayname) {
         $thisselected = ($selected > '' && $selected == strtolower($value)) ? ' selected="selected"' : '';
         $class_var = (isset($option_class_arr[$value])) ? ' class="' . $option_class_arr[$value] . '" ' : '';
         $opts[] = '<option value="'.htmlentities($value, ENT_QUOTES)
                        .'"'.$thisselected.$class_var.'>'.ucwords($displayname).'</option>';
     }

     // various select tag attribute values
     $onchange = (($onchange = trim($onchange)) > '')
               ? " onchange=\"$onchange\""
               : ''
               ;
     $id = ($selectid = strval($selectid))
               ? " id=\"{$selectid}\""
               : ''
               ;
     $readonly = ($readonly == 1)
               ? ' readonly="readonly"'
               : ''
               ;

     return "<select name=\"{$selectname}\" {$selectHTMLattribs}{$id}{$onchange}{$readonly}>".
            join('', $opts).
            '</select>';
}

>
> Thanks!
> Sue
>

attached mail follows:


teaching noobs to output html while (oun intended) looping thru a
result set is counter-productive. discuss.

Adrian Bruce wrote:
> Something along these lines will work fine
>
> <?php
> $query = mysql_query("select dates from table ") or die (mysql_error());
>
> echo"<select name='test'>";
>
> while ($row = mysql_fetch_array($query, MYSQL_NUM)){
> echo"<option value='$row[0]'>$row[1]</option>";
>
> }
> echo"</select>";
> ?>
>
> Regards
> Ade
>
> Sue wrote:
>
>> Hello,
>>
>> We have a form that contains a Select option for a listing of
>> available dates for the user to choose from. Right now we have to
>> manually change the dates within the form's Selection list as new
>> dates become available to choose from. We currently store these
>> available dates in our database, and am wondering if we can somehow
>> extract these dates from the table to display in our form? This would
>> eliminate alot of maintenance needed to this form. If anyone has any
>> ideas as to reference material etc. that I may look which would give
>> me an idea how to do this using PHP, I'd appreciate it!
>>
>> Thanks!
>> Sue
>>
>>
>

attached mail follows:


[snip]
teaching noobs to output html while (oun intended) looping thru a
result set is counter-productive. discuss.
[/snip]

Why is this counter-productive?

attached mail follows:


Jochem,

Jochem Maas wrote:
> teaching noobs to output html while (oun intended) looping thru a
> result set is counter-productive. discuss.

I disagree, however, I do believe attention should be drawn to reasons
why doing so might be considered bad practice.

Even the longest journeys start with small steps, and asking someone new
to PHP to separate various tiers might put them off.

David
--
David Grant
http://www.grant.org.uk/

attached mail follows:


Jay Blanchard wrote:
> [snip]
> teaching noobs to output html while (oun intended) looping thru a
> result set is counter-productive. discuss.
> [/snip]
>
> Why is this counter-productive?

it's a shit way of doing things - with the added bonus that it usually
comes with shit output (as non-validating, bare-minimum-to-get-it-working
HTML).

is that enough 'why' to start a discussion ;-) probably not :-)

attached mail follows:


[snip]
> [snip]
> teaching noobs to output html while (oun intended) looping thru a
> result set is counter-productive. discuss.
> [/snip]
>
> Why is this counter-productive?

it's a shit way of doing things - with the added bonus that it usually
comes with shit output (as non-validating, bare-minimum-to-get-it-working
HTML).

is that enough 'why' to start a discussion ;-) probably not :-)
[/snip]

If not, then give us some more. :)

As to why the HTML would be non-validating it would only be because it
wasn't formatted properly in the output.

Let's look at it another way, why 70-80 lines of code when 4 will do it
properly when done correctly?

attached mail follows:


the quickest solution and one that is easy to understand, I am no php
expert and have never claimed as such so why 'noob'?

Why is this such a poor method? if i type the HTML to be outputted
correctly then what validation is required? also I think Someone new
would run from your proposed solution

Jochem Maas wrote:

> teaching noobs to output html while (oun intended) looping thru a
> result set is counter-productive. discuss.
>
> Adrian Bruce wrote:
>
>> Something along these lines will work fine
>>
>> <?php
>> $query = mysql_query("select dates from table ") or die (mysql_error());
>>
>> echo"<select name='test'>";
>>
>> while ($row = mysql_fetch_array($query, MYSQL_NUM)){
>> echo"<option value='$row[0]'>$row[1]</option>";
>>
>> }
>> echo"</select>";
>> ?>
>>
>> Regards
>> Ade
>>
>> Sue wrote:
>>
>>> Hello,
>>>
>>> We have a form that contains a Select option for a listing of
>>> available dates for the user to choose from. Right now we have to
>>> manually change the dates within the form's Selection list as new
>>> dates become available to choose from. We currently store these
>>> available dates in our database, and am wondering if we can somehow
>>> extract these dates from the table to display in our form? This
>>> would eliminate alot of maintenance needed to this form. If anyone
>>> has any ideas as to reference material etc. that I may look which
>>> would give me an idea how to do this using PHP, I'd appreciate it!
>>>
>>> Thanks!
>>> Sue
>>>
>>>
>>
>

attached mail follows:


[snip]Let's look at it another way, why 70-80 lines of code when 4 will do it
properly when done correctly?[/snip]

I agree with this line of thinking especially for a new person to php.

When I first read the solution that was so long I thought to myself "great and this person is new to php and now they are going to be scared of php."

I really think one of the appeals of php is it's simplicity of getting things done and getting those things done quickly.

Yes it's great having one function to output every select html form but is it really necessary?

attached mail follows:


David Grant wrote:
> Jochem,
>
> Jochem Maas wrote:
>
>>teaching noobs to output html while (oun intended) looping thru a
>>result set is counter-productive. discuss.
>
>
> I disagree, however, I do believe attention should be drawn to reasons
> why doing so might be considered bad practice.

1. your looping a result set which involves a db connection - lots
of pontential things that could go wrong...

2. its not a centralized 'solution' - code reuse is a good thing.

3. we should encourage people to aim a little higher?

>
> Even the longest journeys start with small steps, and asking someone new
> to PHP to separate various tiers might put them off.

which I could spin as a positive thing - raising the lowest commom denominator
so to speak. besides Sue was the one that came with the many-in-one question
(i.e. how to a dynamically generate a select box AND how do I grab data from
a DB).

>
> David

attached mail follows:


Jochem,

Jochem Maas wrote:
> David Grant wrote:
> 1. your looping a result set which involves a db connection - lots
> of pontential things that could go wrong...

Absolutely, and lots of lessons to learn too.

> 2. its not a centralized 'solution' - code reuse is a good thing.

However, what use is code reuse when you're using it only once. If you
need to perform the same function again, then refactor the existing code.

> 3. we should encourage people to aim a little higher?

I imagine my first PHP script with a database connection probably looked
much like Adrian's solution, and writing lots and lots of PHP has taught
be some best practices that I now stick to. However, being told that I
need to write reusable functions for iterating a resultset would've had
me running off to another scripting language in a heartbeat.

Tell people to aim higher, sure, but let them make their own mind up,
make their own mistakes and learn from them. :)

>>
>> Even the longest journeys start with small steps, and asking someone new
>> to PHP to separate various tiers might put them off.
>
> which I could spin as a positive thing - raising the lowest commom
> denominator
> so to speak. besides Sue was the one that came with the many-in-one
> question
> (i.e. how to a dynamically generate a select box AND how do I grab data
> from
> a DB).

I'm sure you're not being elitist, but where do you place the bar?
Should PHP be made a language that only the experienced can get into?
That sounds like a policy that would only harm the PHP community.

David
--
David Grant
http://www.grant.org.uk/

attached mail follows:


Jay Paulson (CE CEN) wrote:
> [snip]Let's look at it another way, why 70-80 lines of code when 4 will do it
> properly when done correctly?[/snip]

4 * 20 = 80
so after having created 20 dynamic select boxes the function wins it.
I really don't think that performance here is the issue - one should tackle
that with suitable caching not writing unmanagable speed-freak-code.

on top of that there is a high chance that the 4 lines will be copy/pasted
quite often - a great way to replicate small little errors. in contrast to the
function which keeps the 'template' HMTL output (of the select box) in
a single place (handy for making site wide changes - for instance all a requirement
that means all selectboxes must have a certain class attribute value?)

another advantage of the function is that it takes into account
attributes/functionality that you might not need in this particular case now -
but might come in handy. using the function means not having to hack stuff
in later)

>
> I agree with this line of thinking especially for a new person to php.
>
> When I first read the solution that was so long I thought to myself "great and this person is new to php and now they are going to be scared of php."

Sue ....

DON'T PANIC (sorry for the lack of friendly letters)

(the fear argument doesn't wash with me btw; if Sue has more questions she should fire away!)
(with regard to fear: go read some Krishnamurti or have children or something - either you go
mad or you get over it ;-)

>
> I really think one of the appeals of php is it's simplicity of getting things done and getting those things done quickly.
>
> Yes it's great having one function to output every select html form but is it really necessary?

sheesh - it's not [YouMustBeJokingIfYouThinkDevelopingWithThisIs]QuickForm
(the 'YouMustBeJokingIfYouThinkDevelopingWithThisIs' is silent ;-)

>

attached mail follows:


Adrian Bruce wrote:
> the quickest solution and one that is easy to understand, I am no php
> expert and have never claimed as such so why 'noob'?
>
> Why is this such a poor method? if i type the HTML to be outputted
> correctly then what validation is required? also I think Someone new
> would run from your proposed solution

I don't really care if she runs. actually if she is liable to run then
that probably saves us here a lot of 'silly' questions ;-)

her original question:

"Is there a way to display data from database for Select Options in a form?"

the short answer is: 'yes'
but the way her original question was posted suggests that maybe she has
_absolutely_ no idea about how to use php... I mean google is able to
help her in theory:

http://www.google.com/search?num=100&q=generate+dynamic+select+box+PHP

either she has no idea what to search for or she was to lazy to try -
if the former then she should have not be ashamed to keep asking away, if
the latter then, well, who cares.

the reason I gave her what might be more than she can chew (the function)
was because:

a, her initial question was a bit vague (or rather broad)
b, to show that there can be a little more to generating dynamic elements
like select box.
c, to encourage generic code.
d, test her and she what her reaction is (hopefully she won't run away; instead
maybe she'll come back with a more specific question and DB data extraction)**

** heck I'm on this list for fun :-)

>
> Jochem Maas wrote:
>
>> teaching noobs to output html while (oun intended) looping thru a
>> result set is counter-productive. discuss.
>>
>> Adrian Bruce wrote:
>>
>>> Something along these lines will work fine
>>>
>>> <?php
>>> $query = mysql_query("select dates from table ") or die (mysql_error());
>>>
>>> echo"<select name='test'>";
>>>
>>> while ($row = mysql_fetch_array($query, MYSQL_NUM)){
>>> echo"<option value='$row[0]'>$row[1]</option>";
>>>
>>> }
>>> echo"</select>";
>>> ?>
>>>
>>> Regards
>>> Ade
>>>
>>> Sue wrote:
>>>
>>>> Hello,
>>>>
>>>> We have a form that contains a Select option for a listing of
>>>> available dates for the user to choose from. Right now we have to
>>>> manually change the dates within the form's Selection list as new
>>>> dates become available to choose from. We currently store these
>>>> available dates in our database, and am wondering if we can somehow
>>>> extract these dates from the table to display in our form? This
>>>> would eliminate alot of maintenance needed to this form. If anyone
>>>> has any ideas as to reference material etc. that I may look which
>>>> would give me an idea how to do this using PHP, I'd appreciate it!
>>>>
>>>> Thanks!
>>>> Sue
>>>>
>>>>
>>>
>>

attached mail follows:


You mean like...

$Link = mysql_connect("Host", "User", "Pass");
mysql_select_db("MyDB");
$Datefield = "Dates";
$Select = mysql_query("SELECT * FROM `Table` WHERE `".$Dates."` LIKE *");
$MySelect = "<select onChange='WhateverJavascript()' id='whateverId'>"
While($Row = mysql_fetch_assoc($Select)) {
  //Adds each date to the select where the value is also equal to the date
  //You can use an increment as well for the value, or whatever you want
  $MySelect .= "<option
value='".$Row[$Datefield]."'>".$Row[$Datefield]."</option>";
}
$MySelect .= "</select>";
mysql_close($Link);

On 1/10/06, Jochem Maas <jochemiamjochem.com> wrote:
>
> Sue wrote:
> > Hello,
> >
> > We have a form that contains a Select option for a listing of available
> > dates for the user to choose from. Right now we have to manually change
> the
> > dates within the form's Selection list as new dates become available to
> > choose from. We currently store these available dates in our database,
> and
> > am wondering if we can somehow extract these dates from the table to
> display
> > in our form? This would eliminate alot of maintenance needed to this
> form.
> > If anyone has any ideas as to reference material etc. that I may look
> which
> > would give me an idea how to do this using PHP, I'd appreciate it!
>
> I am guessing that your php skills are not that hot. filling a select box
> is php 101.... here is function that generates a selectbox based on the
> given
> 'data' - now you have to go and figure out how to build the array $items
> (which is passed as the first arg to this function) from the data in your
> table:
>
> /** selectTag()
> * generate an html select list using the given $items as options.
> *
> * param array $items - list of items to display as options
> * param array $selected - value of select item in $items
> * param string $selectname - value of select tag's name attribute
> * param numeric $addnone - add a 'blank' option to the top of the
> list
> * (different types depending on valuepassed)
> * param string $onchange - value of select tag's onchange attribute
> * param string $selectid - value of select tag's id attribute
> * param boolean $readonly - whether the select tag is readsonly or
> not
> * param array $readonly - whether the select tag is readsonly or
> not
> * param boolean $option_class_arr - optional CSS class names for
> individual option tags
> * param string $selectHTMLattribs - passthru HTML (attributes for the
> select tag)
> *
> * return string
> */
> function selectTag($items, $selected = '', $selectname = '',
> $addnone = 0, $onchange = '', $selectid = '',
> $readonly = 0, $option_class_arr = array(),
> $selectHTMLattribs = '')
> {
> // must have an array of items
> if (!is_array($items)) {
> return '';
> }
>
> // determine the value of the selected item
> $selected = strtolower(trim($selected));
>
> // list of options we will generate
> $opts = array();
>
> // add item with value 0 ?
> $add_none_value = 0;
> switch ( $addnone ) {
> case '1': // item display = 'none'
> $zero_id_item = getStr('None');
> break;
> case '3': // item display = '0'
> $zero_id_item = getStr('zero_digit');
> break;
> case '2': // item display = 'all'
> case '4': // item display = 'all <digit>' e.g. 'all 3'
> $zero_id_item = getStr('All');
> break;
> default:
> if(!empty($addnone) && $addnone != '0') {
> if(is_array($addnone)) {
> list($add_none_value, $zero_id_item) =
> each($addnone);
> } else {
> // here we can drop in a custom 'blank' item:
> $zero_id_item = $addnone;
> }
> }
> break;
> }
> if (isset($zero_id_item)) {
> $thisselected = ($selected > '') ? '' : ' selected="selected"';
> // FIX THE NEXT LINE - BUT NOT IMPORTANT
> $opts[] = '<option value="'.htmlentities($add_none_value,
> ENT_QUOTES).'"'
> .$thisselected'>'.ucwords($zero_id_item).'</option>';
> }
>
> $thisselected = '';
> foreach ($items as $value => $displayname) {
> $thisselected = ($selected > '' && $selected ==
> strtolower($value)) ? ' selected="selected"' : '';
> $class_var = (isset($option_class_arr[$value])) ? ' class="' .
> $option_class_arr[$value] . '" ' : '';
> $opts[] = '<option value="'.htmlentities($value, ENT_QUOTES)
>
> .'"'.$thisselected.$class_var.'>'.ucwords($displayname).'</option>';
> }
>
> // various select tag attribute values
> $onchange = (($onchange = trim($onchange)) > '')
> ? " onchange=\"$onchange\""
> : ''
> ;
> $id = ($selectid = strval($selectid))
> ? " id=\"{$selectid}\""
> : ''
> ;
> $readonly = ($readonly == 1)
> ? ' readonly="readonly"'
> : ''
> ;
>
> return "<select name=\"{$selectname}\"
> {$selectHTMLattribs}{$id}{$onchange}{$readonly}>".
> join('', $opts).
> '</select>';
> }
>
>
> >
> > Thanks!
> > Sue
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
-----BEGIN PGP MESSAGE-----
The One and Only DarkX
-----END PGP MESSAGE-----
-----BEGIN PGP SIGNATURE----
owGbwMvMwCRoO3M+/7fM0iLG07JJDE4vrReHZKQq+OelKiTmpQDpnEoFl8Si7Aiu
DntmVpD8BpgGQabIGob5ToUFGnFlWgz8cj6zPulrPMrfdI2ZYX7wx/++aeWli6aY
7ZqsahKeKc789DAA
=k1EI
-----END PGP SIGNATURE-----

attached mail follows:


David Grant wrote:
> Jochem,
>
> Jochem Maas wrote:
>
>>David Grant wrote:
>>1. your looping a result set which involves a db connection - lots
>>of pontential things that could go wrong...
>
>
> Absolutely, and lots of lessons to learn too.

by that argument your own children shouldn't be sent to
school; and rather than showing then the kitchen stove one should
stick them in the garden with lots of sticks and wait until they learn
how to make fire on their own. (ok that was just to make the point - by
no means am I trying to offend!)

granted that some background is needed to give context to the
rationale (of my point 1 above). although it's questionable as
to have useful the background info could be given the ammount of
peripheral knowledge is required to make sense of some of the issues.

>
>
>>2. its not a centralized 'solution' - code reuse is a good thing.
>
>
> However, what use is code reuse when you're using it only once. If you
> need to perform the same function again, then refactor the existing code.

you don't really think I wrote that function for her do you?
hopefully Sue got that too. I saw her email, I had the file in question
close at hand, I cut/paste & hit send - done.

besides I doubt that this will be the last dynamic select box Sue will want
to create (assuming she stick with this kind of work).

>
>
>>3. we should encourage people to aim a little higher?
>
>
> I imagine my first PHP script with a database connection probably looked
> much like Adrian's solution, and writing lots and lots of PHP has taught

which is no argument for poluting the public space with even more code of
that ilk.

> be some best practices that I now stick to. However, being told that I

ever heard of the concept of learning from _other_ peoples mistakes? ;-)

> need to write reusable functions for iterating a resultset would've had
> me running off to another scripting language in a heartbeat.

I'd did tell her she had to use a function - quite clearly she was offered
something that nobody disputes will work as far as it goes.

>
> Tell people to aim higher, sure, but let them make their own mind up,

I said encourage - which is doen by example rather than with a proverbial stick.

> make their own mistakes and learn from them. :)

yeah so if Sue speaks I'll listen - Sue you seem to have carte blanche to
rip me to shreds so what are you waiting for :-)

>
>
>>>Even the longest journeys start with small steps, and asking someone new
>>>to PHP to separate various tiers might put them off.
>>
>>which I could spin as a positive thing - raising the lowest commom
>>denominator
>>so to speak. besides Sue was the one that came with the many-in-one
>>question
>>(i.e. how to a dynamically generate a select box AND how do I grab data
>>from
>>a DB).
>
>
> I'm sure you're not being elitist, but where do you place the bar?

I think I post enough stuff here to rule out major elitism.
the only real bar I would place is that people are making an effort to
research/investigate and document their problems before asking someone
here for a solution.

to be honest Sue's question was vague, contained 'many' implicits and
showed no indication of having researched the issue. but heck she's female
so I let it pass this time ;-)

the bar has nothing to do with skill and everything to do with effort.

> Should PHP be made a language that only the experienced can get into?

no not at all - but I do feel that answers on mailing lists should
be quality controlled to some extent - that way more of the correct
assumptions and good practices get through to _us_ programmers.

the bar to entry is low with php - that doen't mean we should encourage
to stay at that low level once they are in. n'est pas?

> That sounds like a policy that would only harm the PHP community.

indeed.

>
> David

attached mail follows:


On 1/10/06, Sue <skot1twcny.rr.com> wrote:
> Hello,
>
> We have a form that contains a Select option for a listing of available
> dates for the user to choose from. Right now we have to manually change the
> dates within the form's Selection list as new dates become available to
> choose from. We currently store these available dates in our database, and
> am wondering if we can somehow extract these dates from the table to display
> in our form? This would eliminate alot of maintenance needed to this form.
> If anyone has any ideas as to reference material etc. that I may look which
> would give me an idea how to do this using PHP, I'd appreciate it!
How about...

$format = "m/d/Y";
$sql = "SELECT datefield FROM table";
$results = $whatever_db_abstraction_your_using_to_execute__sql($sql);

<select name="date">
<?php
foreach($results AS $result){
echo "<option>".date($format,strtotime($result))."</option>";
}
?>
</select>

http://us2.php.net/manual/en/function.strtotime.php
http://us2.php.net/manual/en/function.date.php

Mike

attached mail follows:


Jochem: Your method is long, probably takes more time to run, and is
therefore inefficient in this circumstance. There is a time and place
for a good solid reusable function, or even a class.

Of course things could go wrong when using mySQL connections, but
things can always go wrong.

Bringing people to use PHP on a higher standard? I am sorry, but that
is simply childish. There are plenty of kids that think their way in
programming is the best possible way, the only good way, and that
everyone else should try to imitate them. They also think that every
problem should be solved in the language they are strongest with.
Eventually one must learn that for every way of doing something, there
are at least 5 other ways. Higher standards? Or YOUR standards?

The situation determines the standards, not the programmer.

On 1/10/06, Mike Smith <mikeosmithgmail.com> wrote:
> On 1/10/06, Sue <skot1twcny.rr.com> wrote:
> > Hello,
> >
> > We have a form that contains a Select option for a listing of available
> > dates for the user to choose from. Right now we have to manually change the
> > dates within the form's Selection list as new dates become available to
> > choose from. We currently store these available dates in our database, and
> > am wondering if we can somehow extract these dates from the table to display
> > in our form? This would eliminate alot of maintenance needed to this form.
> > If anyone has any ideas as to reference material etc. that I may look which
> > would give me an idea how to do this using PHP, I'd appreciate it!
> How about...
>
> $format = "m/d/Y";
> $sql = "SELECT datefield FROM table";
> $results = $whatever_db_abstraction_your_using_to_execute__sql($sql);
>
> <select name="date">
> <?php
> foreach($results AS $result){
> echo "<option>".date($format,strtotime($result))."</option>";
> }
> ?>
> </select>
>
> http://us2.php.net/manual/en/function.strtotime.php
> http://us2.php.net/manual/en/function.date.php
>
> Mike
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

attached mail follows:


 Thanks for the info

-----Original Message-----
From: tedd [mailto:teddsperling.com]
Sent: Monday, January 09, 2006 3:26 PM
To: php-generallists.php.net; Mark Steudel
Subject: Re: [PHP] Floating numbers truncating to two digits without
rounding

>I am calculating things like tax and want to format them so they only
>have 2 digits past the decimal point. I've been using sprintf but just
>noticed that it tends to round up. I want the same functionlity without
rounding.

Mark:

Rounding?

You can try round(), such as:

<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?>

But, as you can see, this rounds up (not the best).

You may want to consider that there is more than one way to round a number.
For example, there is no completely accurate solution for rounding any real
number. If you want absolute precision, then you must use absolute numbers
to whatever precision they are. However, this may not be obtainable because
of continuos numbers like pi. As such, you may be forced to round.

There are several different algorithms for rounding, such as truncation,
floor (rounding down), ceiling (round up), common, and statistical. None are
perfect, but some are more prone to errors than others. The least prone to
error is the statistical, please review:

"Statisticians method of rounding":

http://en.wikipedia.org/wiki/Rounding

And, if you ignore rounding, please review:

http://www.ima.umn.edu/~arnold/disasters/disasters.html

http://catless.ncl.ac.uk/php/risks/search.php?query=rounding

tedd

--
----------------------------------------------------------------------------
----
http://sperling.com/

attached mail follows:


sprintf creates a string ready for you to manipulate. So does
number_format. Pick whatever is best for your purpose.

See http://uk2.php.net/manual/en/function.sprintf.php and
http://uk2.php.net/manual/en/function.number-format.php for more info.

Gerry

On 1/10/06, Mark Steudel <marknetriver.net> wrote:
> Can I do this all with sprintf or do I then need to convert it to a string
> and chop off what I don't want?
>
> -----Original Message-----
> From: Gerry Danen [mailto:gdanengmail.com]
> Sent: Monday, January 09, 2006 3:35 PM
> To: php-generallists.php.net
> Subject: Re: [PHP] Floating numbers truncating to two digits without
> rounding
>
> Mark,
>
> Why not use sprintf() with an arbitrary large number of decimals and then
> discard all but the 2 you want. I.e., format with 10 decimals and then drop
> the last 8.
>
>

attached mail follows:


> Hello,
>
> I might have to start doing some automated image editing or rezising with
> PHP. I've never done anything like this before so I would need some
> guidelines to get started. Basically what sections of the manual to read and
> what tools need to be installed to the server side to get things like this
> done. Are there any websites about this issue, other than php.net, that
> might provide help to beginners? Thanks for your assistance!

http://phpcommunity.org/gazette/2005/aug/imgresize.html
http://phpcommunity.org/gazette/2005/jun/img_with_php.html

--
Raj Shekhar
blog : http://rajshekhar.net/blog home : http://rajshekhar.net
Disclaimer : http://rajshekhar.net/disclaimer

attached mail follows:


How do I accomplish this?

We have

<!--#exec cgi="/cgi-bin/script.pl" --> and wish to replace it with a php call.

Similarly we want to hide a js script.

--
Member - Liberal International
This is doctornl2k.ab.ca Ici doctornl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
Canada : Consider carefully whom to vote for on 23 Jan 2006, I choose Liberal!

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

attached mail follows:


[snip]
How do I accomplish this?

We have

<!--#exec cgi="/cgi-bin/script.pl" --> and wish to replace it with a php
call.

Similarly we want to hide a js script.
[/snip]

include()

http://www.php.net/include

attached mail follows:


Dr.

The Doctor wrote:
> <!--#exec cgi="/cgi-bin/script.pl" --> and wish to replace it with a php call.

php.net/exec

> Similarly we want to hide a js script.

You want to disable direct requests to the javascript file? I can't
think of a way that couldn't be trivially circumvented. You're probably
better off obfuscating the code.

David
--
David Grant
http://www.grant.org.uk/

attached mail follows:


On Tue, Jan 10, 2006 at 04:57:51PM +0000, David Grant wrote:
> Dr.
>
> The Doctor wrote:
> > <!--#exec cgi="/cgi-bin/script.pl" --> and wish to replace it with a php call.
>
> php.net/exec
>

I did try <?php exec("path/to/cgi-bin/script.pl",$output); ?>

And got nothing.

Any additional pointers?

> > Similarly we want to hide a js script.
>
> You want to disable direct requests to the javascript file? I can't
> think of a way that couldn't be trivially circumvented. You're probably
> better off obfuscating the code.
>

What about using an iframe approach?
 
> David
> --
> David Grant
> http://www.grant.org.uk/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>

--
Member - Liberal International
This is doctornl2k.ab.ca Ici doctornl2k.ab.ca
God Queen and country! Beware Anti-Christ rising!
Canada : Consider carefully whom to vote for on 23 Jan 2006, I choose Liberal!

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

attached mail follows:


The Doctor wrote:
> On Tue, Jan 10, 2006 at 04:57:51PM +0000, David Grant wrote:
>
>>Dr.
>>
>>The Doctor wrote:
>>
>>><!--#exec cgi="/cgi-bin/script.pl" --> and wish to replace it with a php call.
>>
>>php.net/exec
>>
>
>
> I did try <?php exec("path/to/cgi-bin/script.pl",$output); ?>
>
> And got nothing.
>
> Any additional pointers?

http://us2.php.net/shellexec

>>>Similarly we want to hide a js script.

You can't. You can call it from an external file, but it will still be
accessible to anyone who can copy/paste a URL.

--
John C. Nichel IV
Programmer/System Admin (ÜberGeek)
Dot Com Holdings of Buffalo
716.856.9675
jnicheldotcomholdingsofbuffalo.com

attached mail follows:


I'm trying to call a SOAP service where you pass it a couple of dates and it is supposed to return stuff. My testing code is below along with the errors I'm getting. What's strange is that it's not working in php but it works perfectly in Flash. The request it is sending is only sending one param the $to value and not the $from value. Any idea what's going on?

$from = "06/01/2005"; // some date but what format?
$to = "12/31/2005"; // some date but what format?

$client = new SoapClient("some.wsdl", array("trace" => 1, "exceptions" => 0));

var_dump($client->__getFunctions());
echo "<br><br>";
var_dump($client->__getTypes());
echo "<br><br>";

try {
        print($client->execute($from, $to));
} catch (SoapFault $exception) {
        echo $exception;
}
$client->execute($from, $to);
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";

var_dump($client->execute($from, $to));
echo "<br><br>";

echo "<br><br>";
print($client->__soapCall("execute", array("From" => $from, "to" => $to)));

array(1) { [0]=> string(44) "executeResponse execute(execute $parameters)" }

array(2) { [0]=> string(44) "struct execute { string From; string to; }" [1]=> string(44) "struct executeResponse { string wsReturn; }" }

SoapFault exception: [soapenv:Server.userException] [TeamworksException name='Process: 'HR Training Infomation' ProcessItem: 'Untitled0' Type: 'ITEM'', message='Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected ', line=-1, pos=-1 nested=] in /Library/WebServer/Documents/services/soap-test.php:9 Stack trace: #0 /Library/WebServer/Documents/services/soap-test.php(9): SoapClient->__call('execute', Array) #1 /Library/WebServer/Documents/services/soap-test.php(9): SoapClient->execute('06/01/2005', '12/31/2005') #2 {main}

Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="somens"><SOAP-ENV:Body><ns1:execute/><param1>12/31/2005</param1></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <soapenv:Fault>
   <faultcode>soapenv:Server.userException</faultcode>
   <faultstring>[TeamworksException name=&apos;Process: &apos;HR Training Infomation&apos; ProcessItem: &apos;Untitled0&apos; Type: &apos;ITEM&apos;&apos;, message=&apos;Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected
&apos;, line=-1, pos=-1 nested=&lt;none&gt;]</faultstring>
   <detail/>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

object(SoapFault)#2 (9) { ["message:protected"]=> string(0) "" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(51) "/Library/WebServer/Documents/services/soap-test.php" ["line:protected"]=> int(16) ["trace:private"]=> array(2) { [0]=> array(6) { ["file"]=> string(51) "/Library/WebServer/Documents/services/soap-test.php" ["line"]=> int(16) ["function"]=> string(6) "__call" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(7) "execute" [1]=> array(2) { [0]=> string(10) "06/01/2005" [1]=> string(10) "12/31/2005" } } } [1]=> array(6) { ["file"]=> string(51) "/Library/WebServer/Documents/services/soap-test.php" ["line"]=> int(16) ["function"]=> string(7) "execute" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(10) "06/01/2005" [1]=> string(10) "12/31/2005" } } } ["faultstring"]=> string(300) "[TeamworksException name='Process: 'HR Training Infomation' ProcessItem: 'Untitled0' Type: 'ITEM'', message='Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected ', line=-1, pos=-1 nested=]" ["faultcode"]=> string(28) "soapenv:Server.userException" ["detail"]=> string(0) "" }

SoapFault exception: [soapenv:Server.userException] [TeamworksException name='Process: 'HR Training Infomation' ProcessItem: 'Untitled0' Type: 'ITEM'', message='Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected ', line=-1, pos=-1 nested=] in /Library/WebServer/Documents/services/soap-test.php:17 Stack trace: #0 /Library/WebServer/Documents/services/soap-test.php(17): SoapClient->__soapCall('execute', Array) #1 {main}

attached mail follows:


I got it to work! What I had to do is make an associtive array with the keys being the name of the params that needed to get passed to the 'execute' method that it was calling via soap. Or conversely you could write the $params as objects instead of an array.

Code below:

$params["From"] = "06/01/2005"; // also can use $params->From = "date";
$params["to"] = "12/31/2005"; // also can use $params->to = "date";

$client = new SoapClient("some.wsdl", array("trace" => 1, "exceptions" => 0));

try {
        print($client->execute($params));
} catch (SoapFault $exception) {
        echo $exception;
}

-----Original Message-----
From: Jay Paulson (CE CEN) [mailto:Jay.Paulsonwholefoods.com]
Sent: Tue 1/10/2006 11:32 AM
To: php-generallists.php.net
Subject: [PHP] SOAP Problems.
 
I'm trying to call a SOAP service where you pass it a couple of dates and it is supposed to return stuff. My testing code is below along with the errors I'm getting. What's strange is that it's not working in php but it works perfectly in Flash. The request it is sending is only sending one param the $to value and not the $from value. Any idea what's going on?

$from = "06/01/2005"; // some date but what format?
$to = "12/31/2005"; // some date but what format?

$client = new SoapClient("some.wsdl", array("trace" => 1, "exceptions" => 0));

var_dump($client->__getFunctions());
echo "<br><br>";
var_dump($client->__getTypes());
echo "<br><br>";

try {
        print($client->execute($from, $to));
} catch (SoapFault $exception) {
        echo $exception;
}
$client->execute($from, $to);
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";

var_dump($client->execute($from, $to));
echo "<br><br>";

echo "<br><br>";
print($client->__soapCall("execute", array("From" => $from, "to" => $to)));

array(1) { [0]=> string(44) "executeResponse execute(execute $parameters)" }

array(2) { [0]=> string(44) "struct execute { string From; string to; }" [1]=> string(44) "struct executeResponse { string wsReturn; }" }

SoapFault exception: [soapenv:Server.userException] [TeamworksException name='Process: 'HR Training Infomation' ProcessItem: 'Untitled0' Type: 'ITEM'', message='Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected ', line=-1, pos=-1 nested=] in /Library/WebServer/Documents/services/soap-test.php:9 Stack trace: #0 /Library/WebServer/Documents/services/soap-test.php(9): SoapClient->__call('execute', Array) #1 /Library/WebServer/Documents/services/soap-test.php(9): SoapClient->execute('06/01/2005', '12/31/2005') #2 {main}

Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="somens"><SOAP-ENV:Body><ns1:execute/><param1>12/31/2005</param1></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <soapenv:Fault>
   <faultcode>soapenv:Server.userException</faultcode>
   <faultstring>[TeamworksException name=&apos;Process: &apos;HR Training Infomation&apos; ProcessItem: &apos;Untitled0&apos; Type: &apos;ITEM&apos;&apos;, message=&apos;Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected
&apos;, line=-1, pos=-1 nested=&lt;none&gt;]</faultstring>
   <detail/>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

object(SoapFault)#2 (9) { ["message:protected"]=> string(0) "" ["string:private"]=> string(0) "" ["code:protected"]=> int(0) ["file:protected"]=> string(51) "/Library/WebServer/Documents/services/soap-test.php" ["line:protected"]=> int(16) ["trace:private"]=> array(2) { [0]=> array(6) { ["file"]=> string(51) "/Library/WebServer/Documents/services/soap-test.php" ["line"]=> int(16) ["function"]=> string(6) "__call" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(7) "execute" [1]=> array(2) { [0]=> string(10) "06/01/2005" [1]=> string(10) "12/31/2005" } } } [1]=> array(6) { ["file"]=> string(51) "/Library/WebServer/Documents/services/soap-test.php" ["line"]=> int(16) ["function"]=> string(7) "execute" ["class"]=> string(10) "SoapClient" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(10) "06/01/2005" [1]=> string(10) "12/31/2005" } } } ["faultstring"]=> string(300) "[TeamworksException name='Process: 'HR Training Infomation' ProcessItem: 'Untitled0' Type: 'ITEM'', message='Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected ', line=-1, pos=-1 nested=]" ["faultcode"]=> string(28) "soapenv:Server.userException" ["detail"]=> string(0) "" }

SoapFault exception: [soapenv:Server.userException] [TeamworksException name='Process: 'HR Training Infomation' ProcessItem: 'Untitled0' Type: 'ITEM'', message='Internal Script error: org.mozilla.javascript.WrappedException: WrappedException of ORA-01858: a non-numeric character was found where a numeric was expected ', line=-1, pos=-1 nested=] in /Library/WebServer/Documents/services/soap-test.php:17 Stack trace: #0 /Library/WebServer/Documents/services/soap-test.php(17): SoapClient->__soapCall('execute', Array) #1 {main}

attached mail follows:


I want to add a few lines to the javascript validation function and I was
wondering if anyone had any easy ideas on the easiest way to do it.
 
Should I dig into the classes and edit there, or is there a way to replace
it by extending the class or something.
 
Thanks, Mark

attached mail follows:


Sorry wrong list.

-----Original Message-----
From: Mark Steudel [mailto:marknetriver.net]
Sent: Tuesday, January 10, 2006 10:27 AM
To: php-generallists.php.net
Subject: [PHP] [QF] I would like to change the javascript validation
function

I want to add a few lines to the javascript validation function and I was
wondering if anyone had any easy ideas on the easiest way to do it.
 
Should I dig into the classes and edit there, or is there a way to replace
it by extending the class or something.
 
Thanks, Mark

attached mail follows:


Hello,

I have an old version of php (4.3.2) that is acting rather strangely. I'm
searching two large arrays (approx 22,000 records in each) using
array_diff_key() from the PEAR PHP_Compat library:

        $result = $args[0];
        foreach ($args[0] as $key1 => $value1) {
            for ($i = 1; $i !== $array_count; $i++) {
                foreach ($args[$i] as $key2 => $value2) {
                    if ((string) $key1 === (string) $key2) {