Re: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread Ashley Sheridan
On Mon, 2009-06-15 at 17:38 -0400, PJ wrote:
 Jay Blanchard wrote:
  [snip]
  In what way would this simplify or ease my pain?
  The difficulty, it seems to me, is not in retrieving the rows, but
  rather how to pass the row data to the variables. And since the number
  of rows is variable, I believe that the only way to assign the variables
  is by use of a loop? I think I'm beating my head against the wall for
  nothing... :-(
  [/snip]
 
  You asked for easier. In this way the data is assigned to a usable
  variable right out of the gate and that is an array variable. You can
  actually use it with either mysql_fetch_array or mysql_fetch_row. 
 
  Here is your query;
 
  $sql = SELECT first_name, last_name, book_author.ordinal
FROM author, book_author
WHERE book_author.bookID = $idIN  book_author.authID = author.id
  ORDER BY ordinal;
 
  You need not declare another array, but do it this way instead;
 
 if ($results = mysql_query($sql, $db)) {
  while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
  echo $row['first_name'];
  echo $row['last_name'];

 Then I have to add some loopy thing to assign the values to the
 $variables... a real pita since my variable do not lend themselves too
 well to linear alterations ($varIn, $var2IN, $var3IN... etc... so $i=0
 and $i++ arren't going to be too cooperative here... I guess I'd have to
 change that to $var1IN... and then figure out how to do $var.$i.IN ... I
 already tried, but don't seem to have it right
  etcetera.
  }
  }
 
  The lazy part I will agree with :)

 Well, I shouldn't say it, but laziness is a characteristic of
 intelligence: why do more than you have to when you can be doing
 something else. Actually, I am anything but lazy, I spend innumerable
 hours trying to understand what all this coding is about... searching
 the web and rummaging (and I do mean rummaging) in all the lists and
 posts ... but just going through 20 or 30 listings out of more than
 20,000 is already taxing... much easier to ask on the list... if someone
 can understand my fuzzy questions, they may find the grace and
 generosity to take pity on the ignoramus... ;-)
 And I enjoy the ribbing and the humour ... it's a really very nice list!
 
 
 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php
 
 
Why do you need them in separate variables? Can't you use them using
array syntax elsewhere in your code?

Thanks
Ash
www.ashleysheridan.co.uk


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



Re: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread kranthi
you dont have an alternative. you will have to loop because
mysql_fetch_* functions fetch only one row at a time.

you can use variable variables to achieve the above result (you will
not require this if u use list() or extract() functions)
http://us.php.net/manual/en/language.variables.variable.php

and if you cant do the job with arrays, and u need separate variables
list would be an useful function as suggested earlier.
you may also consider using http://in.php.net/manual/en/function.extract.php

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



RE: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread Ford, Mike
On 15 June 2009 18:07, PJ advised:

 Is there an easier or simpler way to do this?
 code:
 
 $sql = SELECT first_name, last_name, book_author.ordinal
   FROM author, book_author
   WHERE book_author.bookID = $idIN  book_author.authID =
author.id
 ORDER BY ordinal;
 
 $author = array();
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {

 $author[] = $row; }
 }
 $numrows = mysql_num_rows($results);
 switch ($numrows)
 {
 case 5:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
   $first_name2IN = $author[1]['first_name'];
   $last_name2IN = $author[1]['last_name'];
   $first_name3IN = $author[2]['first_name'];
   $last_name3IN = $author[2]['last_name'];
   $first_name4IN = $author[3]['first_name'];
   $last_name4IN = $author[3]['last_name'];
   $first_name5IN = $author[4]['first_name'];
   $last_name5IN = $author[4]['last_name'];
   break;
 case 4:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
 snip

Why not just use $author[0]['first_name'] instead of $first_nameIN (and
so on) in the rest of your code?

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730

   


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

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



Re: [PHP] I2C and PHP

2009-06-16 Thread Per Jessen
Tobias Krieger wrote:

 So, what I need is a way to convert any value between 0 and 255 into a
 string with one byte, e.g
 
 0xff =   (with strlen($data) == 1)
 
 I tried it with:
 
 chr(255) - not successfull
 pack(H and h, 0xff) - not successfull
 decbin(255) - without success
 
 And many more variations
 Any ideas, suggestions,  Thanks!

I tried the following:

$d=chr(255);

$f=fopen('klop','w');
fwrite($f,$d);
fclose($f);

The produces a file called 'klop' containing exactly one byte = 0xFF.
That should work with your /dev/i2c interface as well - if not,
something else is getting in your way. 
 

/Per

-- 
Per Jessen, Zürich (16.9°C)


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



RE: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread Dajve Green

 -Original Message-
 From: PJ [mailto:af.gour...@videotron.ca]
 Sent: 15 June 2009 23:10
 To: php-general@lists.php.net
 Subject: [PHP] populate form input option dropdown box from existing data
 
 I am having difficulties figuring out how enter retrieved data into a
 dropdown box for editing. Here's a snippet:
 ...snip
 select name=categoriesIN[] multiple size=8
 option value=1Civilization/option
 option value=2Monuments, Temples amp; Tombs/option
 option value=3Pharaohs and Queens/option... snip
 
 As I understand it, I need to put an array ( $categoriesIN[] ) somewhere
 in the above code... or do I need to insert a series of value selected
 fields for the values?
 The closest thing to what I need, seems to be in this post:
 http://www.hpfreaks.com/forums/index.php?topic=165215
 But it doesn't appear too inviting... not sure if they ever got it to
 work...
 

Hi,

Something like this should work for you

?php
  // Set up initial values
  // This could be hard-coded or brought in from DB or other source
  $categoriesIN_options = array(1 = 'Civilzation',
  2 = 'Monuments, Temples amp;
Tombs',
  3 = 'Pharaohs and Queens',
  );
  // Create a holder for values posted if you want 
  // to repopulate the form on submission
  $selected_clean   = array();
  // Check for passed values and validate
  if (array_key_exists('categoriesIN',$_REQUEST)) {
// Prevents errors with the foreach 
$passed_categoriesIN = (array)$_POST['categoriesIN'];
foreach ($passed_categoriesIN as $options_key) {
  // If the value isn't in our pre-defined array, handle the error
  if (!array_key_exists($options_key,$categoriesIN_options)) {
// Handle error
continue;
  } 
  $selected_clean[] = $options_key;
}
  }
?
[snip]
select name='categoriesIN' multiple size='8'
  ?php // Loop over the options set above
foreach ($categoriesIN_options as $key = $value) {
  echo option value='{$key}';
  // Repopulate with selected
  if (in_array($key,$selected_clean)) {
echo  selected='selected';
  }
  echo {$value}/option\n;
}
  ?
/select


--

for (thoughts, ramblings  doodles) {
  goto http://dajve.co.uk ;
}


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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread kranthi
the above post points to a 404 page
any ways

as suggested above in_array() will do the trick for you.

i prefer using a template engine like smarty..
http://www.smarty.net/manual/en/language.function.html.options.php
One line of code and you are done

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



[PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Matthew Croud


Hello,

My journey of learning PHP is going well, so i've decided to make a  
small program which works out the difference between two times and  
records the data in a text file.


I've searched the PHP manual for functions which can help me out, and  
I discovered the function Date_diff ( http://uk3.php.net/manual/en/function.date-diff.php 
 )and the class DateTime::diff ( http://uk3.php.net/manual/en/datetime.diff.php 
 )


My question is, how on earth do I use these functions ? I really don't  
understand the manual documentation.


I've just moved onto the subject of classes and so I'm fairly new to  
the concept, although I am following it well.


If someone could explain to me how to use ether of these ( Date_diff  
and DateTime::diff ) I would be VERY grateful.


Thank you so much!
Matt

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



[PHP] Re: looking for source to pull data (price of oil)

2009-06-16 Thread O. Lavell
Kurrent wrote:

 I am just simply looking for the price of nymex crude future ( see
 http://www.bloomberg.com/energy/).
 
 Any sources or other idea would be much appreciated. Thanks!

This seems to work:

?php

ini_set(user_agent, Mozilla/5.0); 
$page = strip_tags(file_get_contents(http://www.bloomberg.com/energy/;));
$search = Nymex Crude Future;
$start = strpos($page, $search) + strlen($search);
$price = floatval(substr($page, $start, 5));

echo($price);

?

It assumes a. the Bloomberg page will stay the same, b. the Nymex price 
will always be 5 characters and c. that this is for private use, because 
Bloomberg is likely going to be very unhappy about you republishing their 
data.

That said, I would personally have no qualms using this for a limited 
scope intranet application for instance.


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



RE: [PHP] fopen() on a network share?

2009-06-16 Thread jenai tomaka

Hi, wht dont you try it with IP, ex: 
fopen('http://11.12.13.14/sharename/folder/file.xml', 'w');

 Date: Mon, 15 Jun 2009 22:51:09 -0400
 From: aball...@gmail.com
 To: nos...@mckenzies.net
 CC: php-general@lists.php.net
 Subject: Re: [PHP] fopen() on a network share?
 
 On Mon, Jun 15, 2009 at 7:24 PM, Shawn McKenzienos...@mckenzies.net wrote:
  Brian Dunning wrote:
  Extra info, in case needed: my code says
 
  fopen('\\servername\sharename\folder\file.xml', 'w');
 
  and it returns Failed to open stream, no such file or directory. I've
  verified that the PHP machine does have unrestricted permissions to that
  share and to the directory. Thanks.
 
 
  On Jun 15, 2009, at 1:39 PM, Brian Dunning wrote:
 
  Running on Windows... I have a network share, \\sharename\foldername,
  and I want to write a file. How do I format the pathname with fopen()
  for this?
 
 
 
  As I remember, you either have to double slash or use the other slash.
 
  servername\\sharename\\folder\\file.xml
 
  or
 
  //servername/sharename/folder/file.xml
 
  --
  Thanks!
  -Shawn
  http://www.spidean.com
 
 
 I think 'servername\sharename\folder\file.xml' will work if you're
 using single quotes around the string. The only slashes that would
 need escaped are the first two since the first slash in '\\' escapes
 the second.
 
 Andrew
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

_
Conheça os novos produtos Windows Live! Clique aqui.
http://www.windowslive.com.br

[PHP] Link to .php page with session

2009-06-16 Thread santel

Hi,

I have a .php page that use sessions and shows a file .FLV by
transcoding, on the fly, from any format video to
FLV using a shell command [ system(/usr/bin/ffmpeg -re -i ./file.wmv -f 
flv -an -sameq -) ].


In a .php page:
case 1): if j put a link to any page without session, all is ok;
case 2): if j put a link to .php page with session --
when j click the link, the link take place only after
system() command execution end.

Is there a way to obtain  case 1) behaviour  also  in case 2)  ?

Thanks

Sante Luciani


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



Re: [PHP] include file in a class with global/parent scope?

2009-06-16 Thread Daniel Kolbo
Martin Scotta wrote:
 Where is $vars? there is no $vars in your code...
 
 You can extract all the global space in the CScope method, it's quite
 simple, but less performant.
 
 
 class CScope {
 
public $vars = 'class scope\n';
 
function cinclude($filename) {
extract( $GLOBALS );
include('vars.php');
echo In class $vars\n;
}
 }
 
 On Sun, Jun 14, 2009 at 1:41 PM, Daniel Kolbo kolb0...@umn.edu
 mailto:kolb0...@umn.edu wrote:
 
 Hello,
 
 I understand the why $vars is not in the global scope, but i was
 wondering if there was a way from within the class file to include a
 file in the parent's scope?
 
 i tried ::include('vars.php'), parent::include('vars.php'), but this
 breaks syntax...
 
 Please consider the following three files:
 
 'scope.class.inc'
 ?php
 class CScope {
 
public $vars = 'class scope\n';
 
function cinclude($filename) {
include('vars.php');
echo In class $vars\n;
}
 }
 ?
 
 'vars.php'
 ?php
 //global $vars;//if this line is uncommented then the desired result is
 achieved however, i don't want to change all the variables to global
 scope (this file is includeded in other files where global scoped
 variables is not desireable).
 $vars = 'vars.php scope\n';
 ?
 
 'scope.php'
 ?php
 include('scope.class.inc');
 $object = new CScope;
 $object-cinclude('vars.php');
 echo In original $vars\n;//$vars is not defined***
 ?
 
 Thanks,
 dK
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 -- 
 Martin Scotta

replace all $var with $vars.  The extract method proposed is the
opposite of what i'm looking to do.  I want to bring the class's include
scope into the calling object's scope.

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



Re: [PHP] include file in a class with global/parent scope?

2009-06-16 Thread Daniel Kolbo
Hello,

I've cleaned up my question a bit.

I want the included file which is called within a method of a class to
have the same scope as the instantiation of the class's object.  That
is, i want a class to include a file in the calling object's scope.  How
would one do this?

'test.php'
?php
class CSomeClass {
 public function cinclude() {
   include('vars.php');
 }
}

$object = new CSomeClass;
$object-cinclude();
echo $vars;//i want this to print 'hi'
include('vars.php');
echo obvious $vars;
?

'vars.php'
?php
$vars = hi;
?

OUTPUT:
Notice: Undefined variable: vars in ...\test.php on line 10
obvious hi

DESIRED OUTPUT:
hi
obvious hi

Thanks,
dK

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



Re: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Matthew Croud

Hi Tom,

Thanks for the reply,  I believe I have a fair understanding of  
functions, and I have followed the example on the PHP manual page ( http://uk3.php.net/manual/en/function.date-diff.php 
 ), ideally I want to know how to use the class DateTime::diff, how  
can I use the DateTime::diff to get the difference between two times/ 
dates ? I suppose then I'm after the syntax


would it be like this for example:
$DIfferenceInTime  = DateTime::diff(10:00,12:32);

Thanks again for helping me out.



On 16 Jun 2009, at 12:33, Tom Chubb wrote:


Matt,
Do you understand how to use functions?
A function is defined like this:

function () {
//code goes here
}

You can pass arguments to be used in a function like this:

function($arg1, $arg2) {
//code goes here
}

In the first example on the following page: 
http://uk3.php.net/manual/en/function.date-diff.php
To call the function you need to provide two arguments: $dtTime1
$dtTime2


To use in a script, you need to first define the function, as per  
the example:


?php

function GetDeltaTime($dtTime1, $dtTime2)
{
  $nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
  $nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));

  $nUXDelta = $nUXDate1 - $nUXDate2;
  $strDeltaTime =  . $nUXDelta/60/60; // sec - hour

  $nPos = strpos($strDeltaTime, .);
  if (nPos !== false)
$strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);

  return $strDeltaTime;
}

?

Then you need to call the function like this:

?php
GetDeltaTime(time1-goes-here, time2-goes-here)
?

And it should spit out the difference.

Code is untested and if you didn't follow that I suggest you read up  
on functions: http://www.w3schools.com/php/php_functions.asp


Hope this helps - I'm probably in a similar situation to you and  
have been dabbling with PHP for a few years just as a hobby but  
thought I'd try and help out.

You'll learn a lot from reading this list as well.

Cheers and good luck,

Tom


2009/6/16 Matthew Croud m...@obviousdigital.com

Hello,

My journey of learning PHP is going well, so i've decided to make a  
small program which works out the difference between two times and  
records the data in a text file.


I've searched the PHP manual for functions which can help me out,  
and I discovered the function Date_diff ( http://uk3.php.net/manual/en/function.date-diff.php 
 )and the class DateTime::diff ( http://uk3.php.net/manual/en/datetime.diff.php 
 )


My question is, how on earth do I use these functions ? I really  
don't understand the manual documentation.


I've just moved onto the subject of classes and so I'm fairly new to  
the concept, although I am following it well.


If someone could explain to me how to use ether of these ( Date_diff  
and DateTime::diff ) I would be VERY grateful.


Thank you so much!
Matt

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






Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com







RE: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Dajve Green

Hi Matthew,

A quick note on the DateTime::diff() method - it's only available as from
PHP 5.3, which is currently in release candidate stage, meaning unless you
have your own server running PHP, it won't be available to use (hopefully -
I would be sceptical of any webhost which rolls out RCs on production
servers).

If you need to know what version of PHP you're running, use:
phpversion() or phpinfo()

 -Original Message-
 From: Matthew Croud [mailto:m...@obviousdigital.com]
 Sent: 16 June 2009 12:42
 To: Tom Chubb
 Cc: PHP General list
 Subject: Re: [PHP] difference between two times? Date_diff and
 DateTime::diff
 
 Hi Tom,
 
 Thanks for the reply,  I believe I have a fair understanding of
 functions, and I have followed the example on the PHP manual page (
 http://uk3.php.net/manual/en/function.date-diff.php
   ), ideally I want to know how to use the class DateTime::diff, how
 can I use the DateTime::diff to get the difference between two times/
 dates ? I suppose then I'm after the syntax
 
 would it be like this for example:
 $DIfferenceInTime  = DateTime::diff(10:00,12:32);
 
 Thanks again for helping me out.
 
 
 
 On 16 Jun 2009, at 12:33, Tom Chubb wrote:
 
  Matt,
  Do you understand how to use functions?
  A function is defined like this:
 
  function () {
  //code goes here
  }
 
  You can pass arguments to be used in a function like this:
 
  function($arg1, $arg2) {
  //code goes here
  }
 
  In the first example on the following page:
 http://uk3.php.net/manual/en/function.date-diff.php
  To call the function you need to provide two arguments: $dtTime1 
  $dtTime2
 
  To use in a script, you need to first define the function, as per
  the example:
 
  ?php
 
  function GetDeltaTime($dtTime1, $dtTime2)
  {
$nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
$nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));
 
$nUXDelta = $nUXDate1 - $nUXDate2;
$strDeltaTime =  . $nUXDelta/60/60; // sec - hour
 
$nPos = strpos($strDeltaTime, .);
if (nPos !== false)
  $strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);
 
return $strDeltaTime;
  }
 
  ?
 
  Then you need to call the function like this:
 
  ?php
  GetDeltaTime(time1-goes-here, time2-goes-here)
  ?
 
  And it should spit out the difference.
 
  Code is untested and if you didn't follow that I suggest you read up
  on functions: http://www.w3schools.com/php/php_functions.asp
 
  Hope this helps - I'm probably in a similar situation to you and
  have been dabbling with PHP for a few years just as a hobby but
  thought I'd try and help out.
  You'll learn a lot from reading this list as well.
 
  Cheers and good luck,
 
  Tom
 
 
  2009/6/16 Matthew Croud m...@obviousdigital.com
 
  Hello,
 
  My journey of learning PHP is going well, so i've decided to make a
  small program which works out the difference between two times and
  records the data in a text file.
 
  I've searched the PHP manual for functions which can help me out,
  and I discovered the function Date_diff (
 http://uk3.php.net/manual/en/function.date-diff.php
   )and the class DateTime::diff (
 http://uk3.php.net/manual/en/datetime.diff.php
   )
 
  My question is, how on earth do I use these functions ? I really
  don't understand the manual documentation.
 
  I've just moved onto the subject of classes and so I'm fairly new to
  the concept, although I am following it well.
 
  If someone could explain to me how to use ether of these ( Date_diff
  and DateTime::diff ) I would be VERY grateful.
 
  Thank you so much!
  Matt
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 Matthew Croud
 Studio
 
 Obvious Print Solutions Limited
 Unit 3 Abbeygate Court
 Stockett Lane
 Maidstone
 Kent
 ME15 0PP
 
 T | 0845 094 9704
 F | 0845 094 9705
 www.obviousprint.com
 
 
 
 



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



Re: [PHP] Link to .php page with session

2009-06-16 Thread Stuart
2009/6/16 santel san...@siscom.it:
 Hi,

 I have a .php page that use sessions and shows a file .FLV by
 transcoding, on the fly, from any format video to
 FLV using a shell command [ system(/usr/bin/ffmpeg -re -i ./file.wmv -f flv
 -an -sameq -) ].

 In a .php page:
 case 1): if j put a link to any page without session, all is ok;
 case 2): if j put a link to .php page with session --
        when j click the link, the link take place only after
        system() command execution end.

 Is there a way to obtain  case 1) behaviour  also  in case 2)  ?

I may have interpreted your problem incorrectly, but I think your
problem is due to the session data not being saved until the script
has finished running, including the system call. To get around this
you can save and close the session before calling system using the
session_write_close [1] function. Note that after calling that you
won't be able to make any other changes to the session data in that
request.

-Stuart

[1] http://php.net/session_write_close

-- 
http://stut.net/

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



Re: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread PJ
Ashley Sheridan wrote:
 On Mon, 2009-06-15 at 17:38 -0400, PJ wrote:
   
 Jay Blanchard wrote:
 
 [snip]
 In what way would this simplify or ease my pain?
 The difficulty, it seems to me, is not in retrieving the rows, but
 rather how to pass the row data to the variables. And since the number
 of rows is variable, I believe that the only way to assign the variables
 is by use of a loop? I think I'm beating my head against the wall for
 nothing... :-(
 [/snip]

 You asked for easier. In this way the data is assigned to a usable
 variable right out of the gate and that is an array variable. You can
 actually use it with either mysql_fetch_array or mysql_fetch_row. 

 Here is your query;

 $sql = SELECT first_name, last_name, book_author.ordinal
   FROM author, book_author
   WHERE book_author.bookID = $idIN  book_author.authID = author.id
 ORDER BY ordinal;

 You need not declare another array, but do it this way instead;

if ($results = mysql_query($sql, $db)) {
 while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
 echo $row['first_name'];
 echo $row['last_name'];
   
   
 Then I have to add some loopy thing to assign the values to the
 $variables... a real pita since my variable do not lend themselves too
 well to linear alterations ($varIn, $var2IN, $var3IN... etc... so $i=0
 and $i++ arren't going to be too cooperative here... I guess I'd have to
 change that to $var1IN... and then figure out how to do $var.$i.IN ... I
 already tried, but don't seem to have it right
 
 etcetera.
 }
 }

 The lazy part I will agree with :)
   
   
 Well, I shouldn't say it, but laziness is a characteristic of
 intelligence: why do more than you have to when you can be doing
 something else. Actually, I am anything but lazy, I spend innumerable
 hours trying to understand what all this coding is about... searching
 the web and rummaging (and I do mean rummaging) in all the lists and
 posts ... but just going through 20 or 30 listings out of more than
 20,000 is already taxing... much easier to ask on the list... if someone
 can understand my fuzzy questions, they may find the grace and
 generosity to take pity on the ignoramus... ;-)
 And I enjoy the ribbing and the humour ... it's a really very nice list!


 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php


 
 Why do you need them in separate variables? Can't you use them using
 array syntax elsewhere in your code?
Basically, I don't know how else to handle inserting and updating random
number of authors. Each book in the db may have up to 5 authors. I
imagine there is a simpler way to do it; I just don't have the knowledge
or experience or the time to learn another way. I'd be happy to have you
look at the code and hear some feedback. It's probably a miracle that
the site is working... ;-)
Oh, it's www.ptahhotep.com - my daughter's egyptology site; I just
migrated from pure (almost) html to php/mysql/css and am just doing the
finishing touches now - the edit page.

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread PJ
Ford, Mike wrote:
 On 15 June 2009 18:07, PJ advised:

   
 Is there an easier or simpler way to do this?
 code:

 $sql = SELECT first_name, last_name, book_author.ordinal
   FROM author, book_author
   WHERE book_author.bookID = $idIN  book_author.authID =
 
 author.id
   
 ORDER BY ordinal;

 $author = array();
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
 

   
 $author[] = $row; }
 }
 $numrows = mysql_num_rows($results);
 switch ($numrows)
 {
 case 5:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
   $first_name2IN = $author[1]['first_name'];
   $last_name2IN = $author[1]['last_name'];
   $first_name3IN = $author[2]['first_name'];
   $last_name3IN = $author[2]['last_name'];
   $first_name4IN = $author[3]['first_name'];
   $last_name4IN = $author[3]['last_name'];
   $first_name5IN = $author[4]['first_name'];
   $last_name5IN = $author[4]['last_name'];
   break;
 case 4:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
 snip
 

 Why not just use $author[0]['first_name'] instead of $first_nameIN (and
 so on) in the rest of your code?

   
I probably should have explained in greater detail: there are up to 5
authors for each book in the db and the insert and update fields in the
form input needs the different variables as each author is treated
separately. I'm not sure if there is another way to do it.

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread Eddie Drapkin
I'm going to assume that your table is setup to have the rows BookID and
AuthorName, adjust accordinging:

function makeInsertQuery(array $authors, $bookId) {

$sql = INSERT INTO book_authors (BookID, AuthorName) VALUES ('$bookId', ';

foreach($authors as $author) {
$author = mysql_real_escape_string($author);
}

if(!ctype_digit($bookId)) {
   return false;
}

$sql .= implode(', '$bookid'), (', $authors); // Eric Foo', '123'), ('John
Bar', '123'), ('Ricky Bam', '123'), (';

$sql = substr($sql, 0, -4);

return $sql;
}

On Tue, Jun 16, 2009 at 8:50 AM, PJ af.gour...@videotron.ca wrote:

 Ashley Sheridan wrote:
  On Mon, 2009-06-15 at 17:38 -0400, PJ wrote:
 
  Jay Blanchard wrote:
 
  [snip]
  In what way would this simplify or ease my pain?
  The difficulty, it seems to me, is not in retrieving the rows, but
  rather how to pass the row data to the variables. And since the number
  of rows is variable, I believe that the only way to assign the
 variables
  is by use of a loop? I think I'm beating my head against the wall for
  nothing... :-(
  [/snip]
 
  You asked for easier. In this way the data is assigned to a usable
  variable right out of the gate and that is an array variable. You can
  actually use it with either mysql_fetch_array or mysql_fetch_row.
 
  Here is your query;
 
  $sql = SELECT first_name, last_name, book_author.ordinal
FROM author, book_author
WHERE book_author.bookID = $idIN  book_author.authID =
 author.id
  ORDER BY ordinal;
 
  You need not declare another array, but do it this way instead;
 
 if ($results = mysql_query($sql, $db)) {
  while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
  echo $row['first_name'];
  echo $row['last_name'];
 
 
  Then I have to add some loopy thing to assign the values to the
  $variables... a real pita since my variable do not lend themselves too
  well to linear alterations ($varIn, $var2IN, $var3IN... etc... so $i=0
  and $i++ arren't going to be too cooperative here... I guess I'd have to
  change that to $var1IN... and then figure out how to do $var.$i.IN ... I
  already tried, but don't seem to have it right
 
  etcetera.
  }
  }
 
  The lazy part I will agree with :)
 
 
  Well, I shouldn't say it, but laziness is a characteristic of
  intelligence: why do more than you have to when you can be doing
  something else. Actually, I am anything but lazy, I spend innumerable
  hours trying to understand what all this coding is about... searching
  the web and rummaging (and I do mean rummaging) in all the lists and
  posts ... but just going through 20 or 30 listings out of more than
  20,000 is already taxing... much easier to ask on the list... if someone
  can understand my fuzzy questions, they may find the grace and
  generosity to take pity on the ignoramus... ;-)
  And I enjoy the ribbing and the humour ... it's a really very nice list!
 
 
  --
  Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
  -
  Phil Jourdan --- p...@ptahhotep.com
 http://www.ptahhotep.com
 http://www.chiccantine.com/andypantry.php
 
 
 
  Why do you need them in separate variables? Can't you use them using
  array syntax elsewhere in your code?
 Basically, I don't know how else to handle inserting and updating random
 number of authors. Each book in the db may have up to 5 authors. I
 imagine there is a simpler way to do it; I just don't have the knowledge
 or experience or the time to learn another way. I'd be happy to have you
 look at the code and hear some feedback. It's probably a miracle that
 the site is working... ;-)
 Oh, it's www.ptahhotep.com - my daughter's egyptology site; I just
 migrated from pure (almost) html to php/mysql/css and am just doing the
 finishing touches now - the edit page.

 --
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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




Re: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Matthew Croud

Hi Dajve and Tom,

Thanks again, I totally didn't realise that this function is yet to be  
implemented in the mainstream PHP,


So is there no function that exists in vanilla PHP that can take two  
dates/times and supply the difference ?
If there isn't I do apologise, i've been talking to my friend who does  
ASP.net and he said he was sure there is for PHP.






On 16 Jun 2009, at 13:11, Dajve Green wrote:



Hi Matthew,

A quick note on the DateTime::diff() method - it's only available as  
from
PHP 5.3, which is currently in release candidate stage, meaning  
unless you
have your own server running PHP, it won't be available to use  
(hopefully -

I would be sceptical of any webhost which rolls out RCs on production
servers).

If you need to know what version of PHP you're running, use:
phpversion() or phpinfo()


-Original Message-
From: Matthew Croud [mailto:m...@obviousdigital.com]
Sent: 16 June 2009 12:42
To: Tom Chubb
Cc: PHP General list
Subject: Re: [PHP] difference between two times? Date_diff and
DateTime::diff

Hi Tom,

Thanks for the reply,  I believe I have a fair understanding of
functions, and I have followed the example on the PHP manual page (
http://uk3.php.net/manual/en/function.date-diff.php
 ), ideally I want to know how to use the class DateTime::diff, how
can I use the DateTime::diff to get the difference between two times/
dates ? I suppose then I'm after the syntax

would it be like this for example:
$DIfferenceInTime  = DateTime::diff(10:00,12:32);

Thanks again for helping me out.



On 16 Jun 2009, at 12:33, Tom Chubb wrote:


Matt,
Do you understand how to use functions?
A function is defined like this:

function () {
//code goes here
}

You can pass arguments to be used in a function like this:

function($arg1, $arg2) {
//code goes here
}

In the first example on the following page:

http://uk3.php.net/manual/en/function.date-diff.php

To call the function you need to provide two arguments: $dtTime1 
$dtTime2

To use in a script, you need to first define the function, as per
the example:

?php

function GetDeltaTime($dtTime1, $dtTime2)
{
 $nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
 $nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));

 $nUXDelta = $nUXDate1 - $nUXDate2;
 $strDeltaTime =  . $nUXDelta/60/60; // sec - hour

 $nPos = strpos($strDeltaTime, .);
 if (nPos !== false)
   $strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);

 return $strDeltaTime;
}

?

Then you need to call the function like this:

?php
GetDeltaTime(time1-goes-here, time2-goes-here)
?

And it should spit out the difference.

Code is untested and if you didn't follow that I suggest you read up
on functions: http://www.w3schools.com/php/php_functions.asp

Hope this helps - I'm probably in a similar situation to you and
have been dabbling with PHP for a few years just as a hobby but
thought I'd try and help out.
You'll learn a lot from reading this list as well.

Cheers and good luck,

Tom


2009/6/16 Matthew Croud m...@obviousdigital.com

Hello,

My journey of learning PHP is going well, so i've decided to make a
small program which works out the difference between two times and
records the data in a text file.

I've searched the PHP manual for functions which can help me out,
and I discovered the function Date_diff (

http://uk3.php.net/manual/en/function.date-diff.php

)and the class DateTime::diff (

http://uk3.php.net/manual/en/datetime.diff.php

)

My question is, how on earth do I use these functions ? I really
don't understand the manual documentation.

I've just moved onto the subject of classes and so I'm fairly new to
the concept, although I am following it well.

If someone could explain to me how to use ether of these ( Date_diff
and DateTime::diff ) I would be VERY grateful.

Thank you so much!
Matt

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






Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com








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



Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com







RE: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread Ford, Mike
On 16 June 2009 13:58, PJ advised:

 Ford, Mike wrote:
 On 15 June 2009 18:07, PJ advised:
 
 
 Is there an easier or simpler way to do this?
 code:
 
 $sql = SELECT first_name, last_name, book_author.ordinal
   FROM author, book_author
   WHERE book_author.bookID = $idIN  book_author.authID =
 
 author.id
 
 ORDER BY ordinal;
 
 $author = array();
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
 
 
 
 $author[] = $row; }
 }
 $numrows = mysql_num_rows($results);
 switch ($numrows)
 {
 case 5:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
   $first_name2IN = ;
   $last_name2IN = $author[1]['last_name'];
   $first_name3IN = $author[2]['first_name'];
   $last_name3IN = $author[2]['last_name'];
   $first_name4IN = $author[3]['first_name'];
   $last_name4IN = $author[3]['last_name'];
   $first_name5IN = $author[4]['first_name'];
   $last_name5IN = $author[4]['last_name'];
   break;
 case 4:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
 snip
 
 
 Why not just use $author[0]['first_name'] instead of $first_nameIN
(and
 so on) in the rest of your code?
 
 
 I probably should have explained in greater detail: there are up to 5
 authors for each book in the db and the insert and update
 fields in the
 form input needs the different variables as each author is treated
 separately. I'm not sure if there is another way to do it.

So? In what way does this invalidate my query?

Wherever you have used $first_nameIN, just use $author[0]['first_name'];
wherever you have used $first_name2IN, just use
$author[1]['first_name']; and so on.

Or is there some other context here that you're not telling us? Perhaps
you need to quote more of your script (except leaving out the humungous
switch!)?

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: m.f...@leedsmet.ac.uk
Tel: +44 113 812 4730



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

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



Re: [PHP] Link to .php page with session

2009-06-16 Thread Daniel Brown
On Tue, Jun 16, 2009 at 08:23, Stuartstut...@gmail.com wrote:

 I may have interpreted your problem incorrectly, but I think your
 problem is due to the session data not being saved until the script
 has finished running, including the system call. To get around this
 you can save and close the session before calling system using the
 session_write_close [1] function. Note that after calling that you
 won't be able to make any other changes to the session data in that
 request.

Stuart (plugwho I saw yesterday is listed as a Twitter API
developer in the official docs, by the way ;-P /plug) hit the nail
right on the head there, Santel.  Until the system() function receives
a return response from the spawned application, it'll hold up the rest
of the page execution.  There are, among others, two ways you could
easily handle this:

1.) Write a wrapper shellscript, for which I'll give a simple
example below.
2.) Use the proc_open()[1] or popen()[2] functions in PHP.

To use a wrapper script is simple, and here's one way of doing it:


?php
// yourfile.php

// Your existing code goes here, replacing the system() call with:
system(./convert.sh file.wmv);

//  and then continue with your code.
?

#!/bin/bash
# convert.sh
# Remember to chmod this to 0755 or similar, allowing it to execute.
nohup /usr/bin/ffmpeg -re -i $1 -f flv -an -sameq -  /dev/null 21 

# End of shellscript.


This requires only that you pass the name of the file to be
encoded, and then sends all of the output from ffmpeg to /dev/null
(including STDERR) and detaches the process from the shell (spawning a
poor-man's daemon ;-P).


Ref:
^1: http://php.net/proc_open
^2: http://php.net/popen

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

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



Re: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Tom Chubb
The first example here may help:
http://us3.php.net/manual/en/function.time.php

2009/6/16 Matthew Croud m...@obviousdigital.com

 Hi Dajve and Tom,

 Thanks again, I totally didn't realise that this function is yet to be
 implemented in the mainstream PHP,

 So is there no function that exists in vanilla PHP that can take two
 dates/times and supply the difference ?
 If there isn't I do apologise, i've been talking to my friend who does
 ASP.net and he said he was sure there is for PHP.






 On 16 Jun 2009, at 13:11, Dajve Green wrote:


 Hi Matthew,

 A quick note on the DateTime::diff() method - it's only available as from
 PHP 5.3, which is currently in release candidate stage, meaning unless you
 have your own server running PHP, it won't be available to use (hopefully
 -
 I would be sceptical of any webhost which rolls out RCs on production
 servers).

 If you need to know what version of PHP you're running, use:
 phpversion() or phpinfo()

  -Original Message-
 From: Matthew Croud [mailto:m...@obviousdigital.com]
 Sent: 16 June 2009 12:42
 To: Tom Chubb
 Cc: PHP General list
 Subject: Re: [PHP] difference between two times? Date_diff and
 DateTime::diff

 Hi Tom,

 Thanks for the reply,  I believe I have a fair understanding of
 functions, and I have followed the example on the PHP manual page (
 http://uk3.php.net/manual/en/function.date-diff.php
  ), ideally I want to know how to use the class DateTime::diff, how
 can I use the DateTime::diff to get the difference between two times/
 dates ? I suppose then I'm after the syntax

 would it be like this for example:
 $DIfferenceInTime  = DateTime::diff(10:00,12:32);

 Thanks again for helping me out.



 On 16 Jun 2009, at 12:33, Tom Chubb wrote:

  Matt,
 Do you understand how to use functions?
 A function is defined like this:

 function () {
 //code goes here
 }

 You can pass arguments to be used in a function like this:

 function($arg1, $arg2) {
 //code goes here
 }

 In the first example on the following page:

 http://uk3.php.net/manual/en/function.date-diff.php

 To call the function you need to provide two arguments: $dtTime1 
 $dtTime2

 To use in a script, you need to first define the function, as per
 the example:

 ?php

 function GetDeltaTime($dtTime1, $dtTime2)
 {
  $nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
  $nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));

  $nUXDelta = $nUXDate1 - $nUXDate2;
  $strDeltaTime =  . $nUXDelta/60/60; // sec - hour

  $nPos = strpos($strDeltaTime, .);
  if (nPos !== false)
   $strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);

  return $strDeltaTime;
 }

 ?

 Then you need to call the function like this:

 ?php
 GetDeltaTime(time1-goes-here, time2-goes-here)
 ?

 And it should spit out the difference.

 Code is untested and if you didn't follow that I suggest you read up
 on functions: http://www.w3schools.com/php/php_functions.asp

 Hope this helps - I'm probably in a similar situation to you and
 have been dabbling with PHP for a few years just as a hobby but
 thought I'd try and help out.
 You'll learn a lot from reading this list as well.

 Cheers and good luck,

 Tom


 2009/6/16 Matthew Croud m...@obviousdigital.com

 Hello,

 My journey of learning PHP is going well, so i've decided to make a
 small program which works out the difference between two times and
 records the data in a text file.

 I've searched the PHP manual for functions which can help me out,
 and I discovered the function Date_diff (

 http://uk3.php.net/manual/en/function.date-diff.php

 )and the class DateTime::diff (

 http://uk3.php.net/manual/en/datetime.diff.php

 )

 My question is, how on earth do I use these functions ? I really
 don't understand the manual documentation.

 I've just moved onto the subject of classes and so I'm fairly new to
 the concept, although I am following it well.

 If someone could explain to me how to use ether of these ( Date_diff
 and DateTime::diff ) I would be VERY grateful.

 Thank you so much!
 Matt

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





 Matthew Croud
 Studio

 Obvious Print Solutions Limited
 Unit 3 Abbeygate Court
 Stockett Lane
 Maidstone
 Kent
 ME15 0PP

 T | 0845 094 9704
 F | 0845 094 9705
 www.obviousprint.com







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


 Matthew Croud
 Studio

 Obvious Print Solutions Limited
 Unit 3 Abbeygate Court
 Stockett Lane
 Maidstone
 Kent
 ME15 0PP

 T | 0845 094 9704
 F | 0845 094 9705
 www.obviousprint.com








-- 
Tom Chubb
t...@tomchubb.com | tomch...@gmail.com
07912 202846


RE: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread jenai tomaka

You can try like this,

$row = stored data;
  
and write the options like this
option value=id (id == $row ? selected : ) /option


Yuri Yarlei.




 From: m...@dajve.co.uk
 To: af.gour...@videotron.ca; php-general@lists.php.net
 Date: Tue, 16 Jun 2009 09:33:49 +0100
 Subject: RE: [PHP] populate form input option dropdown box from existing data
 
 
  -Original Message-
  From: PJ [mailto:af.gour...@videotron.ca]
  Sent: 15 June 2009 23:10
  To: php-general@lists.php.net
  Subject: [PHP] populate form input option dropdown box from existing data
  
  I am having difficulties figuring out how enter retrieved data into a
  dropdown box for editing. Here's a snippet:
  ...snip
  select name=categoriesIN[] multiple size=8
  option value=1Civilization/option
  option value=2Monuments, Temples amp; Tombs/option
  option value=3Pharaohs and Queens/option... snip
  
  As I understand it, I need to put an array ( $categoriesIN[] ) somewhere
  in the above code... or do I need to insert a series of value selected
  fields for the values?
  The closest thing to what I need, seems to be in this post:
  http://www.hpfreaks.com/forums/index.php?topic=165215
  But it doesn't appear too inviting... not sure if they ever got it to
  work...
  
 
 Hi,
 
 Something like this should work for you
 
 ?php
   // Set up initial values
   // This could be hard-coded or brought in from DB or other source
   $categoriesIN_options = array(1 = 'Civilzation',
 2 = 'Monuments, Temples amp;
 Tombs',
 3 = 'Pharaohs and Queens',
 );
   // Create a holder for values posted if you want 
   // to repopulate the form on submission
   $selected_clean = array();
   // Check for passed values and validate
   if (array_key_exists('categoriesIN',$_REQUEST)) {
 // Prevents errors with the foreach 
 $passed_categoriesIN = (array)$_POST['categoriesIN'];
 foreach ($passed_categoriesIN as $options_key) {
   // If the value isn't in our pre-defined array, handle the error
   if (!array_key_exists($options_key,$categoriesIN_options)) {
 // Handle error
 continue;
   } 
   $selected_clean[] = $options_key;
 }
   }
 ?
 [snip]
 select name='categoriesIN' multiple size='8'
   ?php // Loop over the options set above
 foreach ($categoriesIN_options as $key = $value) {
   echo option value='{$key}';
   // Repopulate with selected
   if (in_array($key,$selected_clean)) {
 echo  selected='selected';
   }
   echo {$value}/option\n;
 }
   ?
 /select
 
 
 --
 
 for (thoughts, ramblings  doodles) {
   goto http://dajve.co.uk ;
 }
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

_
Conheça os novos produtos Windows Live! Clique aqui.
http://www.windowslive.com.br

Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread tedd

At 6:09 PM -0400 6/15/09, PJ wrote:

I am having difficulties figuring out how enter retrieved data into a
dropdown box for editing. Here's a snippet:
...snip
select name=categoriesIN[] multiple size=8
option value=1Civilization/option
option value=2Monuments, Temples amp; Tombs/option
option value=3Pharaohs and Queens/option... snip

As I understand it, I need to put an array ( $categoriesIN[] ) somewhere
in the above code... or do I need to insert a series of value selected
fields for the values?
The closest thing to what I need, seems to be in this post:
http://www.hpfreaks.com/forums/index.php?topic=165215
But it doesn't appear too inviting... not sure if they ever got it to
work...


Think about it. A Select control returns *one* value and not an 
array. As such you don't need to provide an array to collect a single 
value.


Here's the solution:

HTML

select name=categories 
   option value=1Civilization/option
   option value=2Monuments, Temples amp; Tombs/option
   option value=3Pharaohs and Queens/option
/select

PHP

$category = $_POST['categories'];

The variable $category will contain 1, 2, or 3 after a post form submit.

Try it.

The reference/link you cite above is for a dynamic select control 
that incorporates javascript to populate the second select control. 
It's not a simple select.


If you are looking to understand what basic html does, try this:

http://www.htmlcodetutorial.com/

I often use this site to refresh my failing memory about html stuff.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Form Process Question

2009-06-16 Thread Gary
I have a client that I have made some forms for.  On one of the forms, their 
customers are to registar for a class.  The cost of the class is 195 per 
person.  She would like to have the people be able to have the total cost 
calculated for them before they submit the form. (I already have the cost 
calculated in the email and result page).

I thought about creating a separate form within the original form page that 
could calculate the cost, and process it to itself, I suppose I would need 
to create a session so all the information in the first form is not wiped 
out.

Is there an easier way to do this or is there a way to create this 
calculator that changes upon the input instead of clicking a calculate 
button?

Thanks

Gary




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



Re: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Ian
On 16 Jun 2009 at 14:05, Matthew Croud wrote:

 Hi Dajve and Tom,
 
 Thanks again, I totally didn't realise that this function is yet to be  
 implemented in the mainstream PHP,
 
 So is there no function that exists in vanilla PHP that can take two  
 dates/times and supply the difference ?
 If there isn't I do apologise, i've been talking to my friend who does  
 ASP.net and he said he was sure there is for PHP.

Hi,

This is a quick function that works using unix time stamps.  Its a bit quick 
and messy but 
works ok.  Take a look at the manual page for the strtotime() function to get a 
better idea 
of what it can handle.

?

$Date1_UnixTimeStamp=strtotime(10:10:45);
$Date2_UnixTimeStamp=strtotime(12:45:03);

print_r(DateDiff( $Date1_UnixTimeStamp, $Date2_UnixTimeStamp));

function DateDiff( $Date1_UnixTimeStamp, $Date2_UnixTimeStamp){

$return_difference  = Array(
Days  =  0,
Hours =  0,
Minutes   =  0,
Seconds   =  0
);

$amounts= Array(
Days  =  60*60*24,
Hours =  60*60,
Minutes   =  60
);

$difference = $Date2_UnixTimeStamp - $Date1_UnixTimeStamp;

if($difference = $amounts[Days]){
$return_difference[Days] = floor($difference / 
$amounts[Days]);
$difference -=  $return_difference[Days] * $amounts[Days];
}

if($difference = $amounts[Hours]){
$return_difference[Hours] = floor($difference / 
$amounts[Hours]);
$difference -=   $return_difference[Hours] * 
$amounts[Hours];
}
if($difference = $amounts[Minutes]){
$return_difference[Minutes] = floor($difference / 
$amounts[Minutes]);
$difference -=  $return_difference[Minutes] * 
$amounts[Minutes];
}

$return_difference[Seconds] = $difference;

return $return_difference;
}

?

Regards

Ian
-- 



 On 16 Jun 2009, at 13:11, Dajve Green wrote:
 
 
  Hi Matthew,
 
  A quick note on the DateTime::diff() method - it's only available as  
  from
  PHP 5.3, which is currently in release candidate stage, meaning  
  unless you
  have your own server running PHP, it won't be available to use  
  (hopefully -
  I would be sceptical of any webhost which rolls out RCs on production
  servers).
 
  If you need to know what version of PHP you're running, use:
  phpversion() or phpinfo()
 
  -Original Message-
  From: Matthew Croud [mailto:m...@obviousdigital.com]
  Sent: 16 June 2009 12:42
  To: Tom Chubb
  Cc: PHP General list
  Subject: Re: [PHP] difference between two times? Date_diff and
  DateTime::diff
 
  Hi Tom,
 
  Thanks for the reply,  I believe I have a fair understanding of
  functions, and I have followed the example on the PHP manual page (
  http://uk3.php.net/manual/en/function.date-diff.php
   ), ideally I want to know how to use the class DateTime::diff, how
  can I use the DateTime::diff to get the difference between two times/
  dates ? I suppose then I'm after the syntax
 
  would it be like this for example:
  $DIfferenceInTime  = DateTime::diff(10:00,12:32);
 
  Thanks again for helping me out.
 
 
 
  On 16 Jun 2009, at 12:33, Tom Chubb wrote:
 
  Matt,
  Do you understand how to use functions?
  A function is defined like this:
 
  function () {
  //code goes here
  }
 
  You can pass arguments to be used in a function like this:
 
  function($arg1, $arg2) {
  //code goes here
  }
 
  In the first example on the following page:
  http://uk3.php.net/manual/en/function.date-diff.php
  To call the function you need to provide two arguments: $dtTime1 
  $dtTime2
 
  To use in a script, you need to first define the function, as per
  the example:
 
  ?php
 
  function GetDeltaTime($dtTime1, $dtTime2)
  {
   $nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
   $nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));
 
   $nUXDelta = $nUXDate1 - $nUXDate2;
   $strDeltaTime =  . $nUXDelta/60/60; // sec - hour
 
   $nPos = strpos($strDeltaTime, .);
   if (nPos !== false)
 $strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);
 
   return $strDeltaTime;
  }
 
  ?
 
  Then you need to call the function like this:
 
  ?php
  GetDeltaTime(time1-goes-here, time2-goes-here)
  ?
 
  And it should spit out the difference.
 
  Code is untested and if you didn't follow that I suggest you read up
  on functions: http://www.w3schools.com/php/php_functions.asp
 
  Hope this helps - I'm probably in a similar situation to you and
  have been dabbling with PHP for a few years just as a hobby but
  thought I'd try and help out.
  You'll learn a lot from reading this list as well.
 
  Cheers and good luck,
 
  Tom
 
 
  2009/6/16 Matthew Croud m...@obviousdigital.com
 
  Hello,
 
  My journey of learning PHP is going 

[PHP] PHP5 SOAP...

2009-06-16 Thread Russell Jones
I'm working on a project using SOAP and WS-Security in which I am failing
miserably.

Is there a way to inspect the actual XML, header, etc. that is actually
being sent. I feel like I am constructing the call correctly, and I know
exactly what needs to be sent, but I dont know how to see exactly what is
sent - all I get back are useless errors like not enough information sent,
etc...

Any ideas? Any SOAP pros out there?


Russell Jones
CTO Virante, Inc.
r...@virante.com
919-459-1035


Re: [PHP] how to extract fields from associative array into different variables

2009-06-16 Thread PJ
Ford, Mike wrote:
 On 15 June 2009 18:07, PJ advised:

   
 Is there an easier or simpler way to do this?
 code:

 $sql = SELECT first_name, last_name, book_author.ordinal
   FROM author, book_author
   WHERE book_author.bookID = $idIN  book_author.authID =
 
 author.id
   
 ORDER BY ordinal;

 $author = array();
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_array($results, MYSQL_ASSOC) ) {
 

   
 $author[] = $row; }
 }
 $numrows = mysql_num_rows($results);
 switch ($numrows)
 {
 case 5:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
   $first_name2IN = $author[1]['first_name'];
   $last_name2IN = $author[1]['last_name'];
   $first_name3IN = $author[2]['first_name'];
   $last_name3IN = $author[2]['last_name'];
   $first_name4IN = $author[3]['first_name'];
   $last_name4IN = $author[3]['last_name'];
   $first_name5IN = $author[4]['first_name'];
   $last_name5IN = $author[4]['last_name'];
   break;
 case 4:
   $first_nameIN = $author[0]['first_name'];
   $last_nameIN = $author[0]['last_name'];
 snip
 

 Why not just use $author[0]['first_name'] instead of $first_nameIN (and
 so on) in the rest of your code?
Duh, I think I learned something here... it works! Thank you a
zillion ;-)

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Matthew Croud
Wonderful, thanks Ian for your function, and also thank you Tom for  
having a head scratch on my behalf ;)




On 16 Jun 2009, at 16:20, Ian wrote:


On 16 Jun 2009 at 14:05, Matthew Croud wrote:


Hi Dajve and Tom,

Thanks again, I totally didn't realise that this function is yet to  
be

implemented in the mainstream PHP,

So is there no function that exists in vanilla PHP that can take two
dates/times and supply the difference ?
If there isn't I do apologise, i've been talking to my friend who  
does

ASP.net and he said he was sure there is for PHP.


Hi,

This is a quick function that works using unix time stamps.  Its a  
bit quick and messy but
works ok.  Take a look at the manual page for the strtotime()  
function to get a better idea

of what it can handle.

?

$Date1_UnixTimeStamp=strtotime(10:10:45);
$Date2_UnixTimeStamp=strtotime(12:45:03);

print_r(DateDiff( $Date1_UnixTimeStamp, $Date2_UnixTimeStamp));

function DateDiff( $Date1_UnixTimeStamp, $Date2_UnixTimeStamp){

$return_difference  = Array(
Days=   0,
Hours   =   0,
Minutes =   0,
Seconds =   0
);

$amounts= Array(
Days=   60*60*24,
Hours   =   60*60,
Minutes =   60
);

$difference = $Date2_UnixTimeStamp - $Date1_UnixTimeStamp;

if($difference = $amounts[Days]){
$return_difference[Days] = floor($difference / 
$amounts[Days]);
$difference -=  $return_difference[Days] * $amounts[Days];
}

if($difference = $amounts[Hours]){
		$return_difference[Hours] = floor($difference /  
$amounts[Hours]);

$difference -=   $return_difference[Hours] * 
$amounts[Hours];
}
if($difference = $amounts[Minutes]){
		$return_difference[Minutes] = floor($difference /  
$amounts[Minutes]);

$difference -=  $return_difference[Minutes] * 
$amounts[Minutes];
}

$return_difference[Seconds] = $difference;

return $return_difference;
}

?

Regards

Ian
--




On 16 Jun 2009, at 13:11, Dajve Green wrote:



Hi Matthew,

A quick note on the DateTime::diff() method - it's only available as
from
PHP 5.3, which is currently in release candidate stage, meaning
unless you
have your own server running PHP, it won't be available to use
(hopefully -
I would be sceptical of any webhost which rolls out RCs on  
production

servers).

If you need to know what version of PHP you're running, use:
phpversion() or phpinfo()


-Original Message-
From: Matthew Croud [mailto:m...@obviousdigital.com]
Sent: 16 June 2009 12:42
To: Tom Chubb
Cc: PHP General list
Subject: Re: [PHP] difference between two times? Date_diff and
DateTime::diff

Hi Tom,

Thanks for the reply,  I believe I have a fair understanding of
functions, and I have followed the example on the PHP manual page (
http://uk3.php.net/manual/en/function.date-diff.php
), ideally I want to know how to use the class DateTime::diff, how
can I use the DateTime::diff to get the difference between two  
times/

dates ? I suppose then I'm after the syntax

would it be like this for example:
$DIfferenceInTime  = DateTime::diff(10:00,12:32);

Thanks again for helping me out.



On 16 Jun 2009, at 12:33, Tom Chubb wrote:


Matt,
Do you understand how to use functions?
A function is defined like this:

function () {
//code goes here
}

You can pass arguments to be used in a function like this:

function($arg1, $arg2) {
//code goes here
}

In the first example on the following page:

http://uk3.php.net/manual/en/function.date-diff.php

To call the function you need to provide two arguments: $dtTime1 
$dtTime2

To use in a script, you need to first define the function, as per
the example:

?php

function GetDeltaTime($dtTime1, $dtTime2)
{
$nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
$nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));

$nUXDelta = $nUXDate1 - $nUXDate2;
$strDeltaTime =  . $nUXDelta/60/60; // sec - hour

$nPos = strpos($strDeltaTime, .);
if (nPos !== false)
  $strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);

return $strDeltaTime;
}

?

Then you need to call the function like this:

?php
GetDeltaTime(time1-goes-here, time2-goes-here)
?

And it should spit out the difference.

Code is untested and if you didn't follow that I suggest you  
read up

on functions: http://www.w3schools.com/php/php_functions.asp

Hope this helps - I'm probably in a similar situation to you and
have been dabbling with PHP for a few years just as a hobby but
thought I'd try and help out.
You'll learn a lot from reading this list as well.

Cheers and good luck,

Tom


2009/6/16 Matthew Croud m...@obviousdigital.com

Hello,

My journey of learning PHP is going well, so i've decided to  
make a

small program which works out 

RE: [PHP] PHP5 SOAP...

2009-06-16 Thread bruce
hi russell...

isn't the actual soap data/packet that's being sent over the wire viewable
via an app like livehttpheaders... (at least from firefox)

or are you looking for something in much more detail...



-Original Message-
From: rjon...@gmail.com [mailto:rjon...@gmail.com]on Behalf Of Russell
Jones
Sent: Tuesday, June 16, 2009 8:22 AM
To: PHP General
Subject: [PHP] PHP5 SOAP...


I'm working on a project using SOAP and WS-Security in which I am failing
miserably.

Is there a way to inspect the actual XML, header, etc. that is actually
being sent. I feel like I am constructing the call correctly, and I know
exactly what needs to be sent, but I dont know how to see exactly what is
sent - all I get back are useless errors like not enough information sent,
etc...

Any ideas? Any SOAP pros out there?


Russell Jones
CTO Virante, Inc.
r...@virante.com
919-459-1035


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



Re: [PHP] populate form input option dropdown box from existingdata

2009-06-16 Thread Shawn McKenzie
tedd wrote:
 At 6:09 PM -0400 6/15/09, PJ wrote:
 I am having difficulties figuring out how enter retrieved data into a
 dropdown box for editing. Here's a snippet:
 ...snip
 select name=categoriesIN[] multiple size=8
 option value=1Civilization/option
 option value=2Monuments, Temples amp; Tombs/option
 option value=3Pharaohs and Queens/option... snip

 As I understand it, I need to put an array ( $categoriesIN[] ) somewhere
 in the above code... or do I need to insert a series of value selected
 fields for the values?
 The closest thing to what I need, seems to be in this post:
 http://www.hpfreaks.com/forums/index.php?topic=165215
 But it doesn't appear too inviting... not sure if they ever got it to
 work...
 
 Think about it. A Select control returns *one* value and not an array.
 As such you don't need to provide an array to collect a single value.
 
 Here's the solution:
 
 HTML
 
 select name=categories 
option value=1Civilization/option
option value=2Monuments, Temples amp; Tombs/option
option value=3Pharaohs and Queens/option
 /select
 
 PHP
 
 $category = $_POST['categories'];
 
 The variable $category will contain 1, 2, or 3 after a post form submit.
 
 Try it.
 
 The reference/link you cite above is for a dynamic select control that
 incorporates javascript to populate the second select control. It's not
 a simple select.
 
 If you are looking to understand what basic html does, try this:
 
 http://www.htmlcodetutorial.com/
 
 I often use this site to refresh my failing memory about html stuff.
 
 Cheers,
 
 tedd
 

He has a multiple select, so the select has to be an array or you just
get one value even if more than one was selected (you just get the last
one).

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

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



Re: [PHP] Form Process Question

2009-06-16 Thread Matthew Giddings
Have you thought about using JavaScript? 

Matt Giddings 
Web Programmer 
Information Technology Services 
Saginaw Valley State University 

http://www.svsu.edu 

- Original Message - 
From: Gary gwp...@ptd.net 
To: php-general@lists.php.net 
Sent: Tuesday, June 16, 2009 11:03:38 AM GMT -05:00 US/Canada Eastern 
Subject: [PHP] Form Process Question 

I have a client that I have made some forms for. On one of the forms, their 
customers are to registar for a class. The cost of the class is 195 per 
person. She would like to have the people be able to have the total cost 
calculated for them before they submit the form. (I already have the cost 
calculated in the email and result page). 

I thought about creating a separate form within the original form page that 
could calculate the cost, and process it to itself, I suppose I would need 
to create a session so all the information in the first form is not wiped 
out. 

Is there an easier way to do this or is there a way to create this 
calculator that changes upon the input instead of clicking a calculate 
button? 

Thanks 

Gary 




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



[PHP] Re: Form Process Question

2009-06-16 Thread Shawn McKenzie
Gary wrote:
 I have a client that I have made some forms for.  On one of the forms, their 
 customers are to registar for a class.  The cost of the class is 195 per 
 person.  She would like to have the people be able to have the total cost 
 calculated for them before they submit the form. (I already have the cost 
 calculated in the email and result page).
 
 I thought about creating a separate form within the original form page that 
 could calculate the cost, and process it to itself, I suppose I would need 
 to create a session so all the information in the first form is not wiped 
 out.
 
 Is there an easier way to do this or is there a way to create this 
 calculator that changes upon the input instead of clicking a calculate 
 button?
 
 Thanks
 
 Gary
 
 
 

You have two options as I see it:

1.  Use some javascript that calculates onchange of the form controls.
2.  Have a continue/submit button that posts back to the same page that
does a calculate on submit and show a confirmation page with the total
and then a finish button.

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

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



Re: [PHP] Form Process Question

2009-06-16 Thread Daniel Brown
On Tue, Jun 16, 2009 at 11:03, Garygwp...@ptd.net wrote:
 I have a client that I have made some forms for.  On one of the forms, their
 customers are to registar for a class.  The cost of the class is 195 per
 person.  She would like to have the people be able to have the total cost
 calculated for them before they submit the form. (I already have the cost
 calculated in the email and result page).

Just to point something out here: based upon the information you
sent to the list, this question sounds ridiculous, because on the
surface, it sounds like, the class is $195, so how should I calculate
this as a total?  ;-P

Sometimes, when doing a project, we forget that *we* know all of
the information, but those with whom we're trying to communicate do
not.  What other figures would be calculated into this?  Is there tax
levied in certain circumstances (like if they live in Pennsylvania)?
Is there an option for registering and paying for multiple
participants on a single order?  Can they pay for more than one class
at once?  Are prices meant to be pulled in real-time from a database
or other remote or dynamic source?

If all of the above questions are no, then it's even easier:

?php
$amount = 195;

setlocale(LC_MONETARY,'en_US');
echo money_format('%n',$amount);
?

If even one of the questions above is answered with a 'yes,' then
you'll want to consider the alternatives and weigh each option.  Maybe
you'll want to use JavaScript, maybe you'll want to do server-side
processing --- maybe a combination of both (i.e. - AJAX) if you need
to pull from the database and want to present the information without
refreshing/reloading a page.

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

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



Re: [PHP] include file in a class with global/parent scope?

2009-06-16 Thread Shawn McKenzie
Daniel Kolbo wrote:
 Hello,
 
 I've cleaned up my question a bit.
 
 I want the included file which is called within a method of a class to
 have the same scope as the instantiation of the class's object.  That
 is, i want a class to include a file in the calling object's scope.  How
 would one do this?
 
 'test.php'
 ?php
 class CSomeClass {
  public function cinclude() {
include('vars.php');
  }
 }
 
 $object = new CSomeClass;
 $object-cinclude();
 echo $vars;//i want this to print 'hi'
 include('vars.php');
 echo obvious $vars;
 ?
 
 'vars.php'
 ?php
 $vars = hi;
 ?
 
 OUTPUT:
 Notice: Undefined variable: vars in ...\test.php on line 10
 obvious hi
 
 DESIRED OUTPUT:
 hi
 obvious hi
 
 Thanks,
 dK

Should get you started:

//one way
?php
class CSomeClass {
 public function cinclude() {
   include('vars.php');
   return get_defined_vars();
 }
}

$object = new CSomeClass;
$inc_vars = $object-cinclude();
echo $inc_vars['vars'];//i want this to print 'hi'

---or---

//another way
?php
class CSomeClass {
 var $inc_vars;
 public function cinclude() {
   include('vars.php');
   $this-inc_vars = get_defined_vars();
 }
}

$object = new CSomeClass;
$object-cinclude();
echo $object-inc_vars['vars'];//i want this to print 'hi'


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

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



Re: [PHP] Form Process Question

2009-06-16 Thread Gary
Thanks for your reply, I dont know js

Gary


Matthew Giddings mcgid...@vmail.svsu.edu wrote in message 
news:1497284708.356841245165474329.javamail.r...@vmailbox1.svsu.edu...
 Have you thought about using JavaScript?

 Matt Giddings
 Web Programmer
 Information Technology Services
 Saginaw Valley State University

 http://www.svsu.edu

 - Original Message - 
 From: Gary gwp...@ptd.net
 To: php-general@lists.php.net
 Sent: Tuesday, June 16, 2009 11:03:38 AM GMT -05:00 US/Canada Eastern
 Subject: [PHP] Form Process Question

 I have a client that I have made some forms for. On one of the forms, 
 their
 customers are to registar for a class. The cost of the class is 195 per
 person. She would like to have the people be able to have the total cost
 calculated for them before they submit the form. (I already have the cost
 calculated in the email and result page).

 I thought about creating a separate form within the original form page 
 that
 could calculate the cost, and process it to itself, I suppose I would need
 to create a session so all the information in the first form is not wiped
 out.

 Is there an easier way to do this or is there a way to create this
 calculator that changes upon the input instead of clicking a calculate
 button?

 Thanks

 Gary




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

 



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



[PHP] Re: Form Process Question

2009-06-16 Thread Gary
2. Yea, I was trying to avoid that.  I am thinking about putting this one 
input form into a separate section, have the action file open in a separate 
window to keep the original (long with lots of required fields) intact, 
maybe even some behavior pop up.

Thanks for your help.

Gary


Shawn McKenzie nos...@mckenzies.net wrote in message 
news:ee.81.31180.26eb7...@pb1.pair.com...
 Gary wrote:
 I have a client that I have made some forms for.  On one of the forms, 
 their
 customers are to registar for a class.  The cost of the class is 195 per
 person.  She would like to have the people be able to have the total cost
 calculated for them before they submit the form. (I already have the cost
 calculated in the email and result page).

 I thought about creating a separate form within the original form page 
 that
 could calculate the cost, and process it to itself, I suppose I would 
 need
 to create a session so all the information in the first form is not wiped
 out.

 Is there an easier way to do this or is there a way to create this
 calculator that changes upon the input instead of clicking a calculate
 button?

 Thanks

 Gary




 You have two options as I see it:

 1.  Use some javascript that calculates onchange of the form controls.
 2.  Have a continue/submit button that posts back to the same page that
 does a calculate on submit and show a confirmation page with the total
 and then a finish button.

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



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



Re: [PHP] Form Process Question

2009-06-16 Thread Gary
My my, someone woke up on the wrong side of the bracket

Acutally, the silliness of the request has not been lost on me or the 
client.  And no, it is a simple 195 times number of people, which is usually 
under 5, so, I understand your recent scratching of the head...

I was thinking/hoping there was some mechanism that would calculate the 
amount without hitting the submit button, something like a OnExit command. 
Something that I would not have to work around the validation feilds being 
lost and without having to make up a couple of new files...

Gary


Daniel Brown danbr...@php.net wrote in message 
news:ab5568160906160858u2e670fc4gcd0749334126e...@mail.gmail.com...
On Tue, Jun 16, 2009 at 11:03, Garygwp...@ptd.net wrote:
 I have a client that I have made some forms for. On one of the forms, 
 their
 customers are to registar for a class. The cost of the class is 195 per
 person. She would like to have the people be able to have the total cost
 calculated for them before they submit the form. (I already have the cost
 calculated in the email and result page).

Just to point something out here: based upon the information you
sent to the list, this question sounds ridiculous, because on the
surface, it sounds like, the class is $195, so how should I calculate
this as a total?  ;-P

Sometimes, when doing a project, we forget that *we* know all of
the information, but those with whom we're trying to communicate do
not.  What other figures would be calculated into this?  Is there tax
levied in certain circumstances (like if they live in Pennsylvania)?
Is there an option for registering and paying for multiple
participants on a single order?  Can they pay for more than one class
at once?  Are prices meant to be pulled in real-time from a database
or other remote or dynamic source?

If all of the above questions are no, then it's even easier:

?php
$amount = 195;

setlocale(LC_MONETARY,'en_US');
echo money_format('%n',$amount);
?

If even one of the questions above is answered with a 'yes,' then
you'll want to consider the alternatives and weigh each option.  Maybe
you'll want to use JavaScript, maybe you'll want to do server-side
processing --- maybe a combination of both (i.e. - AJAX) if you need
to pull from the database and want to present the information without
refreshing/reloading a page.

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



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



RE: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread Dajve Green

Yeah, I used to write that way but found I and others in the team saved a
lot more time troubleshooting and extending the code when returning 6 months
later if it was more verbose. Horses for courses, I guess.

Also, the selected attribute should be selected='selected' to validate
correctly as xhtml. By the same token, looking back at my example, I notice
the multiple attribute of the select should be multiple='multiple' -
apologies for missing that the first time =o)
 

 -Original Message-
 From: jenai tomaka [mailto:gargari...@hotmail.com]
 Sent: 16 June 2009 15:56
 To: m...@dajve.co.uk; af.gour...@videotron.ca; php-general@lists.php.net
 Subject: RE: [PHP] populate form input option dropdown box from existing
 data
 
 
 You can try like this,
 
 $row = stored data;
 
 and write the options like this
 option value=id (id == $row ? selected : ) /option
 
 
 Yuri Yarlei.
 
 
 
 
  From: m...@dajve.co.uk
  To: af.gour...@videotron.ca; php-general@lists.php.net
  Date: Tue, 16 Jun 2009 09:33:49 +0100
  Subject: RE: [PHP] populate form input option dropdown box from existing
 data
 
 
   -Original Message-
   From: PJ [mailto:af.gour...@videotron.ca]
   Sent: 15 June 2009 23:10
   To: php-general@lists.php.net
   Subject: [PHP] populate form input option dropdown box from existing
 data
  
   I am having difficulties figuring out how enter retrieved data into a
   dropdown box for editing. Here's a snippet:
   ...snip
   select name=categoriesIN[] multiple size=8
   option value=1Civilization/option
   option value=2Monuments, Temples amp; Tombs/option
   option value=3Pharaohs and Queens/option... snip
  
   As I understand it, I need to put an array ( $categoriesIN[] )
 somewhere
   in the above code... or do I need to insert a series of value
 selected
   fields for the values?
   The closest thing to what I need, seems to be in this post:
   http://www.hpfreaks.com/forums/index.php?topic=165215
   But it doesn't appear too inviting... not sure if they ever got it to
   work...
  
 
  Hi,
 
  Something like this should work for you
 
  ?php
// Set up initial values
// This could be hard-coded or brought in from DB or other source
$categoriesIN_options = array(1 = 'Civilzation',
2 = 'Monuments, Temples amp;
  Tombs',
3 = 'Pharaohs and Queens',
);
// Create a holder for values posted if you want
// to repopulate the form on submission
$selected_clean   = array();
// Check for passed values and validate
if (array_key_exists('categoriesIN',$_REQUEST)) {
  // Prevents errors with the foreach
  $passed_categoriesIN = (array)$_POST['categoriesIN'];
  foreach ($passed_categoriesIN as $options_key) {
// If the value isn't in our pre-defined array, handle the error
if (!array_key_exists($options_key,$categoriesIN_options)) {
  // Handle error
  continue;
}
$selected_clean[] = $options_key;
  }
}
  ?
  [snip]
  select name='categoriesIN' multiple size='8'
?php // Loop over the options set above
  foreach ($categoriesIN_options as $key = $value) {
echo option value='{$key}';
// Repopulate with selected
if (in_array($key,$selected_clean)) {
  echo  selected='selected';
}
echo {$value}/option\n;
  }
?
  /select
 
 
  --
 
  for (thoughts, ramblings  doodles) {
goto http://dajve.co.uk ;
  }
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 _
 Conheça os novos produtos Windows Live! Clique aqui.
 http://www.windowslive.com.br


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



RE: [PHP] difference between two times? Date_diff and DateTime::diff

2009-06-16 Thread Dajve Green

Also, if you're returning data from MySQL, there are a number of operations
you can perform before it reaches your script:
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html


 

From: Tom Chubb [mailto:tomch...@gmail.com] 
Sent: 16 June 2009 15:55
To: Matthew Croud
Cc: Dajve Green; PHP General list
Subject: Re: [PHP] difference between two times? Date_diff and
DateTime::diff

The first example here may help:
http://us3.php.net/manual/en/function.time.php




2009/6/16 Matthew Croud m...@obviousdigital.com
Hi Dajve and Tom,

Thanks again, I totally didn't realise that this function is yet to be
implemented in the mainstream PHP,

So is there no function that exists in vanilla PHP that can take two
dates/times and supply the difference ?
If there isn't I do apologise, i've been talking to my friend who does
ASP.net and he said he was sure there is for PHP.






On 16 Jun 2009, at 13:11, Dajve Green wrote:

Hi Matthew,

A quick note on the DateTime::diff() method - it's only available as from
PHP 5.3, which is currently in release candidate stage, meaning unless you
have your own server running PHP, it won't be available to use (hopefully -
I would be sceptical of any webhost which rolls out RCs on production
servers).

If you need to know what version of PHP you're running, use:
phpversion() or phpinfo()
-Original Message-
From: Matthew Croud [mailto:m...@obviousdigital.com]
Sent: 16 June 2009 12:42
To: Tom Chubb
Cc: PHP General list
Subject: Re: [PHP] difference between two times? Date_diff and
DateTime::diff

Hi Tom,

Thanks for the reply,  I believe I have a fair understanding of
functions, and I have followed the example on the PHP manual page (
http://uk3.php.net/manual/en/function.date-diff.php
 ), ideally I want to know how to use the class DateTime::diff, how
can I use the DateTime::diff to get the difference between two times/
dates ? I suppose then I'm after the syntax

would it be like this for example:
$DIfferenceInTime  = DateTime::diff(10:00,12:32);

Thanks again for helping me out.



On 16 Jun 2009, at 12:33, Tom Chubb wrote:
Matt,
Do you understand how to use functions?
A function is defined like this:

function () {
//code goes here
}

You can pass arguments to be used in a function like this:

function($arg1, $arg2) {
//code goes here
}

In the first example on the following page:
http://uk3.php.net/manual/en/function.date-diff.php
To call the function you need to provide two arguments: $dtTime1 
$dtTime2

To use in a script, you need to first define the function, as per
the example:

?php

function GetDeltaTime($dtTime1, $dtTime2)
{
 $nUXDate1 = strtotime($dtTime1-format(Y-m-d H:i:s));
 $nUXDate2 = strtotime($dtTime2-format(Y-m-d H:i:s));

 $nUXDelta = $nUXDate1 - $nUXDate2;
 $strDeltaTime =  . $nUXDelta/60/60; // sec - hour

 $nPos = strpos($strDeltaTime, .);
 if (nPos !== false)
  $strDeltaTime = substr($strDeltaTime, 0, $nPos + 3);

 return $strDeltaTime;
}

?

Then you need to call the function like this:

?php
GetDeltaTime(time1-goes-here, time2-goes-here)
?

And it should spit out the difference.

Code is untested and if you didn't follow that I suggest you read up
on functions: http://www.w3schools.com/php/php_functions.asp

Hope this helps - I'm probably in a similar situation to you and
have been dabbling with PHP for a few years just as a hobby but
thought I'd try and help out.
You'll learn a lot from reading this list as well.

Cheers and good luck,

Tom


2009/6/16 Matthew Croud m...@obviousdigital.com

Hello,

My journey of learning PHP is going well, so i've decided to make a
small program which works out the difference between two times and
records the data in a text file.

I've searched the PHP manual for functions which can help me out,
and I discovered the function Date_diff (
http://uk3.php.net/manual/en/function.date-diff.php
)and the class DateTime::diff (
http://uk3.php.net/manual/en/datetime.diff.php
)

My question is, how on earth do I use these functions ? I really
don't understand the manual documentation.

I've just moved onto the subject of classes and so I'm fairly new to
the concept, although I am following it well.

If someone could explain to me how to use ether of these ( Date_diff
and DateTime::diff ) I would be VERY grateful.

Thank you so much!
Matt

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




Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com






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

Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com


-- 
Tom Chubb
t...@tomchubb.com | 

RE: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread Dajve Green
A *multiple* select control, as in Phil's initial request will return an
array, however.


 -Original Message-
 From: tedd [mailto:tedd.sperl...@gmail.com]
 Sent: 16 June 2009 15:58
 To: PJ; php-general@lists.php.net
 Subject: Re: [PHP] populate form input option dropdown box from existing
 data
 
 At 6:09 PM -0400 6/15/09, PJ wrote:
 I am having difficulties figuring out how enter retrieved data into a
 dropdown box for editing. Here's a snippet:
 ...snip
 select name=categoriesIN[] multiple size=8
  option value=1Civilization/option
  option value=2Monuments, Temples amp; Tombs/option
  option value=3Pharaohs and Queens/option... snip
 
 As I understand it, I need to put an array ( $categoriesIN[] ) somewhere
 in the above code... or do I need to insert a series of value selected
 fields for the values?
 The closest thing to what I need, seems to be in this post:
 http://www.hpfreaks.com/forums/index.php?topic=165215
 But it doesn't appear too inviting... not sure if they ever got it to
 work...
 
 Think about it. A Select control returns *one* value and not an
 array. As such you don't need to provide an array to collect a single
 value.
 
 Here's the solution:
 
 HTML
 
 select name=categories 
 option value=1Civilization/option
 option value=2Monuments, Temples amp; Tombs/option
 option value=3Pharaohs and Queens/option
 /select
 
 PHP
 
 $category = $_POST['categories'];
 
 The variable $category will contain 1, 2, or 3 after a post form submit.
 
 Try it.
 
 The reference/link you cite above is for a dynamic select control
 that incorporates javascript to populate the second select control.
 It's not a simple select.
 
 If you are looking to understand what basic html does, try this:
 
 http://www.htmlcodetutorial.com/
 
 I often use this site to refresh my failing memory about html stuff.
 
 Cheers,
 
 tedd
 
 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


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



Re: [PHP] about locale settings

2009-06-16 Thread Per Jessen
Per Jessen wrote:

 When I've set LC_ALL before calling php, why do I need to call
 setlocale() in the script too:
 
 LC_ALL=de_DE.utf8 php -r print strftime('%B');
 June
 
 LC_ALL=de_DE.utf8 php -r setlocale(LC_ALL,''); print strftime('%B');
 Juni
 
 What am I missing here?  I have no problem with the
 setlocale(LC_ALL,'') call, but I'd like to understand why I need it.

Am I the only one to run into these oddball problems?  Doesn't anyone
else use different locales?  I think the above is a bug - php _should_
respect the LC_ALL setting without being specifically poked.


/Per

-- 
Per Jessen, Zürich (20.9°C)


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



Re: [PHP] Form Process Question

2009-06-16 Thread Shawn McKenzie
Gary wrote:
 My my, someone woke up on the wrong side of the bracket
 
 Acutally, the silliness of the request has not been lost on me or the 
 client.  And no, it is a simple 195 times number of people, which is usually 
 under 5, so, I understand your recent scratching of the head...
 
 I was thinking/hoping there was some mechanism that would calculate the 
 amount without hitting the submit button, something like a OnExit command. 
 Something that I would not have to work around the validation feilds being 
 lost and without having to make up a couple of new files...
 

There is, it's called javascript ;-) and for this application it should
be very easy.  Something like this (not tested), or a variation:

script type=text/javascript
function calculateTotal()
{
var qty = document.getElementById('qty').value;
var cost = document.getElementById('cost').value;
document.getElementById('total').value = (qty * cost);
}
/script
/head
body

form ..
input type=hidden id=cost value=195 /
Quantity:
input type=text name=qty id=qty value=0
onchange=calculateTotal() /
Total:
input type=text name=total id=total value=0 /
.
/form

 Gary
 
 
 Daniel Brown danbr...@php.net wrote in message 
 news:ab5568160906160858u2e670fc4gcd0749334126e...@mail.gmail.com...
 On Tue, Jun 16, 2009 at 11:03, Garygwp...@ptd.net wrote:
 I have a client that I have made some forms for. On one of the forms, 
 their
 customers are to registar for a class. The cost of the class is 195 per
 person. She would like to have the people be able to have the total cost
 calculated for them before they submit the form. (I already have the cost
 calculated in the email and result page).
 
 Just to point something out here: based upon the information you
 sent to the list, this question sounds ridiculous, because on the
 surface, it sounds like, the class is $195, so how should I calculate
 this as a total?  ;-P
 
 Sometimes, when doing a project, we forget that *we* know all of
 the information, but those with whom we're trying to communicate do
 not.  What other figures would be calculated into this?  Is there tax
 levied in certain circumstances (like if they live in Pennsylvania)?
 Is there an option for registering and paying for multiple
 participants on a single order?  Can they pay for more than one class
 at once?  Are prices meant to be pulled in real-time from a database
 or other remote or dynamic source?
 
 If all of the above questions are no, then it's even easier:
 
 ?php
 $amount = 195;
 
 setlocale(LC_MONETARY,'en_US');
 echo money_format('%n',$amount);
 ?
 
 If even one of the questions above is answered with a 'yes,' then
 you'll want to consider the alternatives and weigh each option.  Maybe
 you'll want to use JavaScript, maybe you'll want to do server-side
 processing --- maybe a combination of both (i.e. - AJAX) if you need
 to pull from the database and want to present the information without
 refreshing/reloading a page.
 

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

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



Re: [PHP] include file in a class with global/parent scope?

2009-06-16 Thread Shawn McKenzie
Shawn McKenzie wrote:
 Daniel Kolbo wrote:
 Hello,

 I've cleaned up my question a bit.

 I want the included file which is called within a method of a class to
 have the same scope as the instantiation of the class's object.  That
 is, i want a class to include a file in the calling object's scope.  How
 would one do this?

 'test.php'
 ?php
 class CSomeClass {
  public function cinclude() {
include('vars.php');
  }
 }

 $object = new CSomeClass;
 $object-cinclude();
 echo $vars;//i want this to print 'hi'
 include('vars.php');
 echo obvious $vars;
 ?

 'vars.php'
 ?php
 $vars = hi;
 ?

 OUTPUT:
 Notice: Undefined variable: vars in ...\test.php on line 10
 obvious hi

 DESIRED OUTPUT:
 hi
 obvious hi

 Thanks,
 dK
 
 Should get you started:
 
 //one way
 ?php
 class CSomeClass {
  public function cinclude() {
include('vars.php');
return get_defined_vars();
  }
 }
 
 $object = new CSomeClass;
 $inc_vars = $object-cinclude();
 echo $inc_vars['vars'];//i want this to print 'hi'
 
 ---or---
 
 //another way
 ?php
 class CSomeClass {
  var $inc_vars;
  public function cinclude() {
include('vars.php');
$this-inc_vars = get_defined_vars();
  }
 }
 
 $object = new CSomeClass;
 $object-cinclude();
 echo $object-inc_vars['vars'];//i want this to print 'hi'
 
 

Another way off the top of my head:

//vars.php
$vars['something'] = 'hi';
$vars['whatever'] = 'bye';

//test.php
class CSomeClass {
 var $vars;
 public function cinclude() {
   include('vars.php');
   $this-vars = $vars;
 }
}

$object = new CSomeClass;
$object-cinclude();
echo $object-vars['something'];//i want this to print 'hi'

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

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



[PHP] Totally weird behavior trying to download a Mac DMG file

2009-06-16 Thread Brian Dunning
So I've added a product to my online store that's in .DMG format. Most  
of the other files are ZIP or PDF. When someone completes a purchase,  
it downloads the file to them, and this works great:


header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='. 
$file_row[filename].'');

$size = filesize('../../store/files/'.$file_row['filename']);
header('Content-Length: '.$size);
readfile('../../store/files/'.$file_row['filename']);

So I have my DMG file. I've verified that it automounts and behaves  
friendly. If you do a direct download, it mounts on the desktop  
perfectly, and there's all the stuff inside.


However, when I complete a test purchase and download using the above  
code, the DMG file downloads, but then it mounts; the contents are  
copied into the Downloads folder; the image unmounts; and then  
deletes. All the contents are delivered, but not in a desirable way.  
You can see the status change in the Downloads window:


Mounting the image
Copying the image
Unmounting the image
Cleaning up

WTF?



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



[PHP] Re: Totally weird behavior trying to download a Mac DMG file

2009-06-16 Thread Shawn McKenzie
Brian Dunning wrote:
 So I've added a product to my online store that's in .DMG format. Most
 of the other files are ZIP or PDF. When someone completes a purchase, it
 downloads the file to them, and this works great:
 
 header('Content-Type: application/octet-stream');
 header('Content-Disposition: attachment;
 filename='.$file_row[filename].'');
 $size = filesize('../../store/files/'.$file_row['filename']);
 header('Content-Length: '.$size);
 readfile('../../store/files/'.$file_row['filename']);
 
 So I have my DMG file. I've verified that it automounts and behaves
 friendly. If you do a direct download, it mounts on the desktop
 perfectly, and there's all the stuff inside.
 
 However, when I complete a test purchase and download using the above
 code, the DMG file downloads, but then it mounts; the contents are
 copied into the Downloads folder; the image unmounts; and then deletes.
 All the contents are delivered, but not in a desirable way. You can see
 the status change in the Downloads window:
 
 Mounting the image
 Copying the image
 Unmounting the image
 Cleaning up
 
 WTF?
 
 
Sounds like a Mac / Safari feature.

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

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



Re: [PHP] populate form input option dropdown box from existingdata

2009-06-16 Thread tedd

At 10:42 AM -0500 6/16/09, Shawn McKenzie wrote:

He has a multiple select, so the select has to be an array or you just
get one value even if more than one was selected (you just get the last
one).


Okay, it's not that much different than using check-boxes -- here's 
the solution for that:


http://www.webbytedd.com/bbb/check-box-form/index.php

and here's the select solution:

http://www.webbytedd.com/bbb/select-box-form/index.php

The point is to use name=option[] (i.e., name the array) and allow 
the browser to populate the POST array. Then on the php side of 
things, simply pull out the data from the POST array via the array's 
name.


You can see how this is done via the above links.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Form Process Question

2009-06-16 Thread tedd

At 11:03 AM -0400 6/16/09, Gary wrote:

I have a client that I have made some forms for.  On one of the forms, their
customers are to registar for a class.  The cost of the class is 195 per
person.  She would like to have the people be able to have the total cost
calculated for them before they submit the form. (I already have the cost
calculated in the email and result page).

I thought about creating a separate form within the original form page that
could calculate the cost, and process it to itself, I suppose I would need
to create a session so all the information in the first form is not wiped
out.

Is there an easier way to do this or is there a way to create this
calculator that changes upon the input instead of clicking a calculate
button?

Thanks

Gary


Gary:

You could send everything to another form to show the totals, but 
that's not the most user friendly.


The way I would do it is via javascript, like so:

http://webbytedd.com/c/form-calc/

This populates the totals on the fly so that the customers see's the 
total as they pick things.


Of course, you still must: 1) re-evaluate what the use submits on the 
server-side (i.e., never trust client-side for anything); 2) In case 
that the user does not allow javascript to work, then you have to 
plan for that and do it on the server-side anyway for graceful 
degradation.


Cheers,

tedd


--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



[PHP] Re: Totally weird behavior trying to download a Mac DMG file

2009-06-16 Thread tedd

At 1:05 PM -0500 6/16/09, Shawn McKenzie wrote:


  WTF?




Sounds like a Mac / Safari feature.



Yeah, like the most recent Safari update that shows the contents of 
Safari as an open folder on my desktop. I have to put the folder away 
each time, but when I restart it's always there. I can't wait for the 
next update so Apple can fix this bonehead error.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Totally weird behavior trying to download a Mac DMG file

2009-06-16 Thread Brian Dunning

Don't think so, only when I download via the PHP code I posted:

On Jun 16, 2009, at 10:40 AM, Brian Dunning wrote:

 If you do a direct download, it mounts on the desktop perfectly,  
and there's all the stuff inside.





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



Re: [PHP] Form Process Question

2009-06-16 Thread Daniel Brown
On Tue, Jun 16, 2009 at 12:34, Garygwp...@ptd.net wrote:

 I was thinking/hoping there was some mechanism that would calculate the
 amount without hitting the submit button, something like a OnExit command.
 Something that I would not have to work around the validation feilds being
 lost and without having to make up a couple of new files...

http://pilotpig.net/code-library/gary-js.php

You can change the hidden field to a regular text field (even
disable it from editing), a div, or whatever.  Just don't use the
price as a hidden field on the production site.  The above code is for
example only.  Take with food.  Batteries not included.  Cannot be
combined with any other offer.  See store for details.  May cause
cancer.  Women who are pregnant or may become pregnant must not use
this product.  Limit one per customer.  Contains Red Lake #5.  Do not
operate machinery after consuming.  No pets allowed.  Not responsible
for lost or misdirected mail.  Contains tree nuts.  Wash before using.
 Keep out of reach of children.  May cause drowsiness.  Use as
directed.  While supplies last.  Do not inhale.

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

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



RE: [PHP] populate form input option dropdown box from existingdata

2009-06-16 Thread Dajve Green
Ack, yes - my bad. Missed the select name square brackets when I sent my
example.

And yeah, the only real difference between a multiple select and checkbox is
which works best with the UI (and, more often than not, how confused the
concept of multiple selects makes your end-user)

--

for (thoughts, ramblings  doodles) {
  goto http://dajve.co.uk ;
}
 

 -Original Message-
 From: tedd [mailto:tedd.sperl...@gmail.com]
 Sent: 16 June 2009 19:05
 To: php-general@lists.php.net
 Subject: Re: [PHP] populate form input option dropdown box from
 existingdata
 
 At 10:42 AM -0500 6/16/09, Shawn McKenzie wrote:
 He has a multiple select, so the select has to be an array or you just
 get one value even if more than one was selected (you just get the last
 one).
 
 Okay, it's not that much different than using check-boxes -- here's
 the solution for that:
 
 http://www.webbytedd.com/bbb/check-box-form/index.php
 
 and here's the select solution:
 
 http://www.webbytedd.com/bbb/select-box-form/index.php
 
 The point is to use name=option[] (i.e., name the array) and allow
 the browser to populate the POST array. Then on the php side of
 things, simply pull out the data from the POST array via the array's
 name.
 
 You can see how this is done via the above links.
 
 Cheers,
 
 tedd
 
 --
 ---
 http://sperling.com  http://ancientstones.com  http://earthstones.com
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


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



Re: [PHP] about locale settings

2009-06-16 Thread Daniel Brown
On Tue, Jun 16, 2009 at 12:51, Per Jessenp...@computer.org wrote:

 Am I the only one to run into these oddball problems?  Doesn't anyone
 else use different locales?  I think the above is a bug - php _should_
 respect the LC_ALL setting without being specifically poked.

Per;

Sorry, I meant to get back to you the other day.  Do you have 'E'
in your 'EGPCS'?

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

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



Re: [PHP] Form Process Question

2009-06-16 Thread Shawn McKenzie
Daniel Brown wrote:
 On Tue, Jun 16, 2009 at 12:34, Garygwp...@ptd.net wrote:
 I was thinking/hoping there was some mechanism that would calculate the
 amount without hitting the submit button, something like a OnExit command.
 Something that I would not have to work around the validation feilds being
 lost and without having to make up a couple of new files...
 
 http://pilotpig.net/code-library/gary-js.php
 
 You can change the hidden field to a regular text field (even
 disable it from editing), a div, or whatever.  Just don't use the
 price as a hidden field on the production site.  The above code is for
 example only.  Take with food.  Batteries not included.  Cannot be
 combined with any other offer.  See store for details.  May cause
 cancer.  Women who are pregnant or may become pregnant must not use
 this product.  Limit one per customer.  Contains Red Lake #5.  Do not
 operate machinery after consuming.  No pets allowed.  Not responsible
 for lost or misdirected mail.  Contains tree nuts.  Wash before using.
  Keep out of reach of children.  May cause drowsiness.  Use as
 directed.  While supplies last.  Do not inhale.
 

May lead to the condition known as hot dog finger, giant eyeball...

Do not taunt happy fun ball...

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

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



Re: [PHP] Totally weird behavior trying to download a Mac DMG file

2009-06-16 Thread Shawn McKenzie
Brian Dunning wrote:
 Don't think so, only when I download via the PHP code I posted:
 
 On Jun 16, 2009, at 10:40 AM, Brian Dunning wrote:
 
  If you do a direct download, it mounts on the desktop perfectly, and
 there's all the stuff inside.
 
 
 

Use livehttpheaders or some other header capture utility and see what
the difference in the headers are between the dl from the PHP page and
direct download.



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

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



Re: [PHP] about locale settings

2009-06-16 Thread Per Jessen
Daniel Brown wrote:

 On Tue, Jun 16, 2009 at 12:51, Per Jessenp...@computer.org wrote:

 Am I the only one to run into these oddball problems?  Doesn't anyone
 else use different locales?  I think the above is a bug - php
 _should_ respect the LC_ALL setting without being specifically poked.
 
 Per;
 
  Sorry, I meant to get back to you the other day.  Do you have 'E'
  in your 'EGPCS'? 
 

Hi Dan

umm, I had to look that one up - I wasn't sure how to check it, but when
I run:

LC_ALL=de_DE.utf8 php '-r phpinfo()'

I see

Environment

Variable = Value
LC_ALL = de_DE.utf8

Is that what you were after?


/Per

-- 
Per Jessen, Zürich (18.4°C)


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



Re: [PHP] about locale settings

2009-06-16 Thread Daniel Brown
On Tue, Jun 16, 2009 at 15:33, Per Jessenp...@computer.org wrote:

 Environment

 Variable = Value
 LC_ALL = de_DE.utf8

 Is that what you were after?

Sure is.  Unfortunately, that means it's not an environment-import
issue as I had originally suspected.  I'll take a look on one of my
servers and see if I can help you debug the problem in just a few
minutes.

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

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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread PJ
jenai tomaka wrote:
 You can try like this,

 $row = stored data;
  
 and write the options like this
 option value=id (id == $row ? selected : ) /option


 Yuri Yarlei.

 http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8
Yuri, I'm still wet behind the ears on this so I don't quite
understand what you mean by stored data ;  and what does the id
(id==$row?selected:) mean?
I get the idea that this might be translated into something in the code
I have dreamed up - further down.

echo option value=, $row['id'], , $row['category'], /optionbr /;
I suppose that I must add an if clause to insert the selected option for
the categories that are relevant...


Gentlemen,
I have been diligently studying all this and have just returned my
attention to the list, so I've read the replies/inputs and now comment:

BTW, I had some problems with the multiple statement - it does not take
any parameters; it must simply be stated multiple without quotes.

Now, I was happy to learn that it is simpler to populate the insert new
books page dynamically from the db. Much shorter  neater.
It looks to me like the best solution for the edit page is close to what
Yuri suggests.
Since the edit page is very similar to the insert new books page, I
merely need to populate the Select options box slightly differently.
This is the code to populate the insert page:
select name=categoriesIN[] multiple size=8
?php
$sql = SELECT * FROM categories; 
  if ( ( $results = mysql_query($sql, $db) ) !== false ) {
while ( $row = mysql_fetch_assoc($results) ) {
echo option value=, $row['id'], , $row['category'],
/optionbr /;
}
}
?
/select

The problem nowis to find a way to add a conditional clause above that
will insert the option=selected in the output.
The input for this comes from:
// do categories
$sql = SELECT id, category FROM categories, book_categories
WHERE book_categories.bookID = $idIN 
book_categories.categories_id = categories.id;;
if ( ( $results = mysql_query($sql, $db) ) !== false ) {
while ( $row = mysql_fetch_assoc($results) ) {
echo$row['id'], br /;
}
}

This may return any number of category ids so the problem is to figure
out a way to pass the ids from the above code to the right ids in the
first code above.
How  what do I search to match the two ids?

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread Ashley Sheridan
On Tue, 2009-06-16 at 15:48 -0400, PJ wrote:
 jenai tomaka wrote:
  You can try like this,
 
  $row = stored data;
   
  and write the options like this
  option value=id (id == $row ? selected : ) /option
 
 
  Yuri Yarlei.
 
  http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8
 Yuri, I'm still wet behind the ears on this so I don't quite
 understand what you mean by stored data ;  and what does the id
 (id==$row?selected:) mean?
 I get the idea that this might be translated into something in the code
 I have dreamed up - further down.
 
 echo option value=, $row['id'], , $row['category'], /optionbr /;
 I suppose that I must add an if clause to insert the selected option for
 the categories that are relevant...
 
 
 Gentlemen,
 I have been diligently studying all this and have just returned my
 attention to the list, so I've read the replies/inputs and now comment:
 
 BTW, I had some problems with the multiple statement - it does not take
 any parameters; it must simply be stated multiple without quotes.
 
 Now, I was happy to learn that it is simpler to populate the insert new
 books page dynamically from the db. Much shorter  neater.
 It looks to me like the best solution for the edit page is close to what
 Yuri suggests.
 Since the edit page is very similar to the insert new books page, I
 merely need to populate the Select options box slightly differently.
 This is the code to populate the insert page:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories; 
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo option value=, $row['id'], , $row['category'],
 /optionbr /;
 }
 }
 ?
 /select
 
 The problem nowis to find a way to add a conditional clause above that
 will insert the option=selected in the output.
 The input for this comes from:
 // do categories
 $sql = SELECT id, category FROM categories, book_categories
 WHERE book_categories.bookID = $idIN 
 book_categories.categories_id = categories.id;;
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo$row['id'], br /;
 }
 }
 
 This may return any number of category ids so the problem is to figure
 out a way to pass the ids from the above code to the right ids in the
 first code above.
 How  what do I search to match the two ids?
 
 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php
 
 
option value=id (id == $row ? selected : ) /option is
pretty bad HTML, as attributes should always have a value. Personally, I
do something like this as it tends not to confuse the code too much

$selected = ($id == $row)?'selected=selected':'';
print option value=\$id\ $selected /option;


Thanks
Ash
www.ashleysheridan.co.uk


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



[PHP] Problems with apc extension on wamp server.

2009-06-16 Thread Valentinas Bakaitis
Hello!

I am trying to track file upload progress using APC extension.
However, when trying to use, it gives

Fatal error: Call to undefined function apc_fetch() in
C:\wamp\www\old\getprogress.php on line 3

I am using WAMP 2.0, with php 5.2.8
APC extension appear on extensions list and is enabled.

Any ideas what i am doing wrong?

here is the code of getprogress.php:

*
*
$upload = apc_fetch('upload_1');
   if ($upload) {
if ($upload['done'])
$percent = 100;
else if ($upload['total'] == 0)
$percent = 0;
else
$percent = $upload['current'] / $upload['total'] * 100;


Re: [PHP] Totally weird behavior trying to download a Mac DMG file

2009-06-16 Thread Brian Dunning

Good idea, thanks.   :-)

On Jun 16, 2009, at 12:30 PM, Shawn McKenzie wrote:


Use livehttpheaders or some other header capture utility and see what
the difference in the headers are between the dl from the PHP page and
direct download.




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



[PHP] Re: Form Process Question

2009-06-16 Thread Gary
Thanks to everyone for your help (again).  I used the js script the Shawn 
had provided...

(I was ascared of the one Daniel provided.:)

Thanks again for all your help.

Gary


Gary gwp...@ptd.net wrote in message 
news:f3.0c.31180.f54b7...@pb1.pair.com...
I have a client that I have made some forms for.  On one of the forms, 
their customers are to registar for a class.  The cost of the class is 195 
per person.  She would like to have the people be able to have the total 
cost calculated for them before they submit the form. (I already have the 
cost calculated in the email and result page).

 I thought about creating a separate form within the original form page 
 that could calculate the cost, and process it to itself, I suppose I would 
 need to create a session so all the information in the first form is not 
 wiped out.

 Is there an easier way to do this or is there a way to create this 
 calculator that changes upon the input instead of clicking a calculate 
 button?

 Thanks

 Gary


 



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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread PJ
Ashley Sheridan wrote:
 On Tue, 2009-06-16 at 15:48 -0400, PJ wrote:
   
 jenai tomaka wrote:
 
 You can try like this,

 $row = stored data;
  
 and write the options like this
 option value=id (id == $row ? selected : ) /option


 Yuri Yarlei.

 http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8
   
 Yuri, I'm still wet behind the ears on this so I don't quite
 understand what you mean by stored data ;  and what does the id
 (id==$row?selected:) mean?
 I get the idea that this might be translated into something in the code
 I have dreamed up - further down.

 echo option value=, $row['id'], , $row['category'], /optionbr /;
 I suppose that I must add an if clause to insert the selected option for
 the categories that are relevant...


 Gentlemen,
 I have been diligently studying all this and have just returned my
 attention to the list, so I've read the replies/inputs and now comment:

 BTW, I had some problems with the multiple statement - it does not take
 any parameters; it must simply be stated multiple without quotes.

 Now, I was happy to learn that it is simpler to populate the insert new
 books page dynamically from the db. Much shorter  neater.
 It looks to me like the best solution for the edit page is close to what
 Yuri suggests.
 Since the edit page is very similar to the insert new books page, I
 merely need to populate the Select options box slightly differently.
 This is the code to populate the insert page:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories; 
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo option value=, $row['id'], , $row['category'],
 /optionbr /;
 }
 }
 ?
 /select

 The problem nowis to find a way to add a conditional clause above that
 will insert the option=selected in the output.
 The input for this comes from:
 // do categories
 $sql = SELECT id, category FROM categories, book_categories
 WHERE book_categories.bookID = $idIN 
 book_categories.categories_id = categories.id;;
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo$row['id'], br /;
 }
 }

 This may return any number of category ids so the problem is to figure
 out a way to pass the ids from the above code to the right ids in the
 first code above.
 How  what do I search to match the two ids?

 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php


 
 option value=id (id == $row ? selected : ) /option is
 pretty bad HTML, as attributes should always have a value. Personally, I
 do something like this as it tends not to confuse the code too much

 $selected = ($id == $row)?'selected=selected':'';
 print option value=\$id\ $selected /option;
   
I was unable to get any of the suggestions to work, except in_array().
However, the selected item refuses to become highlighted.
code:
select name=categoriesIN[] multiple size=8
?php
$sql = SELECT * FROM categories;
//$selected = ($id == $row)?'selected=selected':'';
  if ( ( $results = mysql_query($sql, $db) ) !== false ) {
while ( $row = mysql_fetch_assoc($results) ) {
if (in_array($row['id'], $ccc)) {
  echo option value=, $row['id'],  selected ,
$row['category'], /optionbr /;
  }
  else echo option value=, $row['id'], ,
$row['category'], /optionbr /;
}
}
?
/select
I can't find anything that explains why the selected item is not
highlighted.

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread Ashley Sheridan
On Tue, 2009-06-16 at 18:19 -0400, PJ wrote:
 Ashley Sheridan wrote:
  On Tue, 2009-06-16 at 15:48 -0400, PJ wrote:

  jenai tomaka wrote:
  
  You can try like this,
 
  $row = stored data;
   
  and write the options like this
  option value=id (id == $row ? selected : ) /option
 
 
  Yuri Yarlei.
 
  http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8

  Yuri, I'm still wet behind the ears on this so I don't quite
  understand what you mean by stored data ;  and what does the id
  (id==$row?selected:) mean?
  I get the idea that this might be translated into something in the code
  I have dreamed up - further down.
 
  echo option value=, $row['id'], , $row['category'], /optionbr 
  /;
  I suppose that I must add an if clause to insert the selected option for
  the categories that are relevant...
 
 
  Gentlemen,
  I have been diligently studying all this and have just returned my
  attention to the list, so I've read the replies/inputs and now comment:
 
  BTW, I had some problems with the multiple statement - it does not take
  any parameters; it must simply be stated multiple without quotes.
 
  Now, I was happy to learn that it is simpler to populate the insert new
  books page dynamically from the db. Much shorter  neater.
  It looks to me like the best solution for the edit page is close to what
  Yuri suggests.
  Since the edit page is very similar to the insert new books page, I
  merely need to populate the Select options box slightly differently.
  This is the code to populate the insert page:
  select name=categoriesIN[] multiple size=8
  ?php
  $sql = SELECT * FROM categories; 
if ( ( $results = mysql_query($sql, $db) ) !== false ) {
  while ( $row = mysql_fetch_assoc($results) ) {
  echo option value=, $row['id'], , $row['category'],
  /optionbr /;
  }
  }
  ?
  /select
 
  The problem nowis to find a way to add a conditional clause above that
  will insert the option=selected in the output.
  The input for this comes from:
  // do categories
  $sql = SELECT id, category FROM categories, book_categories
  WHERE book_categories.bookID = $idIN 
  book_categories.categories_id = categories.id;;
  if ( ( $results = mysql_query($sql, $db) ) !== false ) {
  while ( $row = mysql_fetch_assoc($results) ) {
  echo$row['id'], br /;
  }
  }
 
  This may return any number of category ids so the problem is to figure
  out a way to pass the ids from the above code to the right ids in the
  first code above.
  How  what do I search to match the two ids?
 
  -- 
  Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
  -
  Phil Jourdan --- p...@ptahhotep.com
 http://www.ptahhotep.com
 http://www.chiccantine.com/andypantry.php
 
 
  
  option value=id (id == $row ? selected : ) /option is
  pretty bad HTML, as attributes should always have a value. Personally, I
  do something like this as it tends not to confuse the code too much
 
  $selected = ($id == $row)?'selected=selected':'';
  print option value=\$id\ $selected /option;

 I was unable to get any of the suggestions to work, except in_array().
 However, the selected item refuses to become highlighted.
 code:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories;
 //$selected = ($id == $row)?'selected=selected':'';
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 if (in_array($row['id'], $ccc)) {
   echo option value=, $row['id'],  selected ,
 $row['category'], /optionbr /;
   }
   else echo option value=, $row['id'], ,
 $row['category'], /optionbr /;
 }
 }
 ?
 /select
 I can't find anything that explains why the selected item is not
 highlighted.
 
 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php
 
Have you actually looked at the html this produces to see if any of the
elements are being marked with the selected=selected attribute?

Thanks
Ash
www.ashleysheridan.co.uk


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



Re: [PHP] PHP5 SOAP...

2009-06-16 Thread Tom Rogers
Hi,

Wednesday, June 17, 2009, 1:21:47 AM, you wrote:
RJ I'm working on a project using SOAP and WS-Security in which I am failing
RJ miserably.

RJ Is there a way to inspect the actual XML, header, etc. that is actually
RJ being sent. I feel like I am constructing the call correctly, and I know
RJ exactly what needs to be sent, but I dont know how to see exactly what is
RJ sent - all I get back are useless errors like not enough information sent,
RJ etc...

RJ Any ideas? Any SOAP pros out there?


RJ Russell Jones
RJ CTO Virante, Inc.
RJ r...@virante.com
RJ 919-459-1035

Not a pro but...
Try something like this:
//object to pass function variables
class requestObject {
function requestObject($list) {
foreach($list as $key=$val)
$this-$key = $val;
}
}

$client = new  SoapClient(wsdl.xml, array('login'= login, 'password'= 
password, 'trace'=true));

$soapstruct = new requestObject(array('clientId'=12342, 'leagueId'=0)); //use 
whatever variables are needed
try {
$info = $client-soapFunction($soapstruct);
echo REQUEST:\n . $client-__getLastRequest() . br /\n;
print_r($info);
} catch (SoapFault $e) {
echo SOAP Fault: .$e-getMessage().br /\n;
echo REQUEST:\n . $client-__getLastRequest() . br /\n;
}

-- 
regards,
Tom


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



[PHP] Re: Issues with APC, cache corruption?

2009-06-16 Thread James McLean
On Mon, Jun 15, 2009 at 9:42 AM, James McLeanjames.mcl...@gmail.com wrote:
 Hi All,

 Over the weekend I setup a test of APC intending to benchmark a Moodle
 installation with various APC settings to see how well I could get it
 to perform. I successfully installed Moodle 1.9 and 2.0 under Apache
 2.2.3 (installed via apt on Ubuntu 9.04), and with PHP 5.2.9 compiled
 from source. I should note, that Ubuntu had an older version of PHP
 installed from apt with Suhosin hardened PHP built in. Moodle 2.0
 required at least PHP 5.2.8, so I uninstalled the original PHP module
 before compiling and installing the 5.2.9.

 No issues there; PHP worked well and performance was (mostly) acceptable.

 Progressed onto installing APC, firstly by downloading the APC 3.1.2
 source from PECL and following the usual 'phpize, configure, make,
 make install' process which worked as expected, stop and start Apache
 and APC was present in my phpinfo();. I started with the reccomended
 PHP config exept with error_display turned on and E_ALL | E_STRICT
 enabled, and also the reccomended APC config also.

 I copied the 'apc.php' from the source tree to my webroot and changed
 the password as suggested.

 The issue arose when I attempted to benchmark my Moodle install with
 'ab' (I realise it only downloads the single page, but it's good
 enough for what I need for now though) and the result was no different
 to before I had installed APC. View the apc.php page, and the only
 page cached is apc.php itself.. Certainly not what I've witnessed in
 the past. Then what would happen was if I viewed my seperate info.php
 page containing simply the opening PHP tag and a single line with
 phpinfo(); in the file - the cache would appear to reset, and it would
 firstly not load the info.php into the cache, it would reset the
 counter on the apc.php file back to 0.

 Through all of this, there was no errors displayed on the screen and
 no errors listed in the Apache error log either. Increased the Apache
 log level up to Debug, and no related information was displayed.
 Moodle itself worked as expected with no errors, and on a seperate
 RHEL installation I have Moodle working with APC and it is caching all
 it's files as expected.

 At this point, I thought it may be an issue with the module I compiled
 myself. I backed up the module, and allowed PECL to install the
 module, it installed 3.0.19. Restarted Apache and verified the version
 was as PECL had built and installed.

 This had no effect, and yeilded the same behaviour.

 I'm stumped as to what the issue could be, however I did see this
 issue of APC not caching files on an installation of Red Hat
 Enterprise Linux in the past - however at the time we assumed it was
 an issue with the framework we were using and due to time constraints
 simply ran without APC and didn't investigate further.

 Has anyone seen this issue in the past and perhaps even rectified it?

 Any information would be appreciated.

As I have not had a response to my question yet, is there anyone who
may be able to shed some light on the issue?

Last night I also tried some different configure options when building
APC but with the same result..

Has anyone seen this behaviour before?

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



Re: [PHP] Problems with apc extension on wamp server.

2009-06-16 Thread Jonathan Tapicer
Hi,

Does the extension appear on a phpinfo()?

Seems like the extension isn't loaded.

Jonathan


On Tue, Jun 16, 2009 at 5:20 PM, Valentinas
Bakaitisv.bakai...@gmail.com wrote:
 Hello!

 I am trying to track file upload progress using APC extension.
 However, when trying to use, it gives

 Fatal error: Call to undefined function apc_fetch() in
 C:\wamp\www\old\getprogress.php on line 3

 I am using WAMP 2.0, with php 5.2.8
 APC extension appear on extensions list and is enabled.

 Any ideas what i am doing wrong?

 here is the code of getprogress.php:

 *
 *
 $upload = apc_fetch('upload_1');
   if ($upload) {
        if ($upload['done'])
            $percent = 100;
        else if ($upload['total'] == 0)
            $percent = 0;
        else
            $percent = $upload['current'] / $upload['total'] * 100;


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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread PJ
Ashley Sheridan wrote:
 On Tue, 2009-06-16 at 18:19 -0400, PJ wrote:
   
 Ashley Sheridan wrote:
 
 On Tue, 2009-06-16 at 15:48 -0400, PJ wrote:
   
   
 jenai tomaka wrote:
 
 
 You can try like this,

 $row = stored data;
  
 and write the options like this
 option value=id (id == $row ? selected : ) /option


 Yuri Yarlei.

 http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8
   
   
 Yuri, I'm still wet behind the ears on this so I don't quite
 understand what you mean by stored data ;  and what does the id
 (id==$row?selected:) mean?
 I get the idea that this might be translated into something in the code
 I have dreamed up - further down.

 echo option value=, $row['id'], , $row['category'], /optionbr 
 /;
 I suppose that I must add an if clause to insert the selected option for
 the categories that are relevant...


 Gentlemen,
 I have been diligently studying all this and have just returned my
 attention to the list, so I've read the replies/inputs and now comment:

 BTW, I had some problems with the multiple statement - it does not take
 any parameters; it must simply be stated multiple without quotes.

 Now, I was happy to learn that it is simpler to populate the insert new
 books page dynamically from the db. Much shorter  neater.
 It looks to me like the best solution for the edit page is close to what
 Yuri suggests.
 Since the edit page is very similar to the insert new books page, I
 merely need to populate the Select options box slightly differently.
 This is the code to populate the insert page:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories; 
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo option value=, $row['id'], , $row['category'],
 /optionbr /;
 }
 }
 ?
 /select

 The problem nowis to find a way to add a conditional clause above that
 will insert the option=selected in the output.
 The input for this comes from:
 // do categories
 $sql = SELECT id, category FROM categories, book_categories
 WHERE book_categories.bookID = $idIN 
 book_categories.categories_id = categories.id;;
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo$row['id'], br /;
 }
 }

 This may return any number of category ids so the problem is to figure
 out a way to pass the ids from the above code to the right ids in the
 first code above.
 How  what do I search to match the two ids?

 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php


 
 
 option value=id (id == $row ? selected : ) /option is
 pretty bad HTML, as attributes should always have a value. Personally, I
 do something like this as it tends not to confuse the code too much

 $selected = ($id == $row)?'selected=selected':'';
 print option value=\$id\ $selected /option;
   
   
 I was unable to get any of the suggestions to work, except in_array().
 However, the selected item refuses to become highlighted.
 code:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories;
 //$selected = ($id == $row)?'selected=selected':'';
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 if (in_array($row['id'], $ccc)) {
   echo option value=, $row['id'],  selected ,
 $row['category'], /optionbr /;
   }
   else echo option value=, $row['id'], ,
 $row['category'], /optionbr /;
 }
 }
 ?
 /select
 I can't find anything that explains why the selected item is not
 highlighted.

 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

 
 Have you actually looked at the html this produces to see if any of the
 elements are being marked with the selected=selected attribute?
   
Good thinking; I feel dumb all over again... :-(

Yeah, view source doesn't show any selected words.
Something fishy is going on.

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



[PHP] sloppiness stupidity

2009-06-16 Thread PJ
I'm sorry, guys, but I am really getting po'd.
The irresponsible sloppiness and stupidity is just getting to me.
In my quest for a way to populate a multiple option select box I have
run across so many errors that it's beyond belief... such nonsense as
select for select or select=select ( think this is right, but then
who knows?)  other variations; then theres in_array() that has
explanations about as clear as a cesspool - the way it's explained is
not at all clear, -- and somebody did an in_array($tring, text) -
which is reversed... don't these idiots read what they are putting up on
the internet?
And some of you wonder why I ask stupid questions? Rare, indeed, is the
clear explanation or demonstration. I get the impression that there are
a lot of asholeys out there who learn the less than basic programming
and then forget that even a ignoramus as I can be looking for rather
complicated guidance. The Internet was a great promise, but god is is
overbloated with floating intellectual excrement.
Sorry, but ranting sometimes is good for the psyche. :o

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread PJ
Ashley Sheridan wrote:
 On Tue, 2009-06-16 at 18:19 -0400, PJ wrote:
   
 Ashley Sheridan wrote:
 
 On Tue, 2009-06-16 at 15:48 -0400, PJ wrote:
   
   
 jenai tomaka wrote:
 
 
 You can try like this,

 $row = stored data;
  
 and write the options like this
 option value=id (id == $row ? selected : ) /option


 Yuri Yarlei.

 http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8
   
   
 Yuri, I'm still wet behind the ears on this so I don't quite
 understand what you mean by stored data ;  and what does the id
 (id==$row?selected:) mean?
 I get the idea that this might be translated into something in the code
 I have dreamed up - further down.

 echo option value=, $row['id'], , $row['category'], /optionbr 
 /;
 I suppose that I must add an if clause to insert the selected option for
 the categories that are relevant...


 Gentlemen,
 I have been diligently studying all this and have just returned my
 attention to the list, so I've read the replies/inputs and now comment:

 BTW, I had some problems with the multiple statement - it does not take
 any parameters; it must simply be stated multiple without quotes.

 Now, I was happy to learn that it is simpler to populate the insert new
 books page dynamically from the db. Much shorter  neater.
 It looks to me like the best solution for the edit page is close to what
 Yuri suggests.
 Since the edit page is very similar to the insert new books page, I
 merely need to populate the Select options box slightly differently.
 This is the code to populate the insert page:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories; 
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo option value=, $row['id'], , $row['category'],
 /optionbr /;
 }
 }
 ?
 /select

 The problem nowis to find a way to add a conditional clause above that
 will insert the option=selected in the output.
 The input for this comes from:
 // do categories
 $sql = SELECT id, category FROM categories, book_categories
 WHERE book_categories.bookID = $idIN 
 book_categories.categories_id = categories.id;;
 if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 echo$row['id'], br /;
 }
 }

 This may return any number of category ids so the problem is to figure
 out a way to pass the ids from the above code to the right ids in the
 first code above.
 How  what do I search to match the two ids?

 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php


 
 
 option value=id (id == $row ? selected : ) /option is
 pretty bad HTML, as attributes should always have a value. Personally, I
 do something like this as it tends not to confuse the code too much

 $selected = ($id == $row)?'selected=selected':'';
 print option value=\$id\ $selected /option;
   
   
 I was unable to get any of the suggestions to work, except in_array().
 However, the selected item refuses to become highlighted.
 code:
 select name=categoriesIN[] multiple size=8
 ?php
 $sql = SELECT * FROM categories;
 //$selected = ($id == $row)?'selected=selected':'';
   if ( ( $results = mysql_query($sql, $db) ) !== false ) {
 while ( $row = mysql_fetch_assoc($results) ) {
 if (in_array($row['id'], $ccc)) {
   echo option value=, $row['id'],  selected ,
 $row['category'], /optionbr /;
   }
   else echo option value=, $row['id'], ,
 $row['category'], /optionbr /;
 }
 }
 ?
 /select
 I can't find anything that explains why the selected item is not
 highlighted.

 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- p...@ptahhotep.com
http://www.ptahhotep.com
http://www.chiccantine.com/andypantry.php

 
 Have you actually looked at the html this produces to see if any of the
 elements are being marked with the selected=selected attribute?

 Thanks
 Ash
 www.ashleysheridan.co.uk
   
I just cannot find a way to pass the selected fields to the options script.
Even if I add the selected to all the fields, they show up in the source
code but the fields are still not highlighted.
There has to be a way to get this right??? :'(

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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

RE: [PHP] sloppiness stupidity

2009-06-16 Thread Asher Snyder
While ranting might be good for the psyche there are trained psychiatric 
professionals that will readily listen to your rants. The PHP mailing list is 
not the place to vent. In every large community there will be those with less 
experience than others, and yes, many inexperienced programmers that will do 
whatever it takes to get things working, even if that means copying and pasting 
code they don't understand. Instead of ranting, a more useful approach would be 
to create a post that properly informs a user on how to populate a multiple 
option select box and eventually rank higher than any incorrect postings.

-Original Message-
From: PJ [mailto:af.gour...@videotron.ca] 
Sent: Tuesday, June 16, 2009 8:44 PM
To: php-general@lists.php.net
Subject: [PHP] sloppiness  stupidity

I'm sorry, guys, but I am really getting po'd.
The irresponsible sloppiness and stupidity is just getting to me.
In my quest for a way to populate a multiple option select box I have
run across so many errors that it's beyond belief... such nonsense as
select for select or select=select ( think this is right, but then
who knows?)  other variations; then theres in_array() that has
explanations about as clear as a cesspool - the way it's explained is
not at all clear, -- and somebody did an in_array($tring, text) -
which is reversed... don't these idiots read what they are putting up on
the internet?
And some of you wonder why I ask stupid questions? Rare, indeed, is the
clear explanation or demonstration. I get the impression that there are
a lot of asholeys out there who learn the less than basic programming
and then forget that even a ignoramus as I can be looking for rather
complicated guidance. The Internet was a great promise, but god is is
overbloated with floating intellectual excrement.
Sorry, but ranting sometimes is good for the psyche. :o

-- 
Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
-
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


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



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



[PHP] Re: sloppiness stupidity

2009-06-16 Thread Shawn McKenzie
PJ wrote:
 I'm sorry, guys, but I am really getting po'd.
 The irresponsible sloppiness and stupidity is just getting to me.
 In my quest for a way to populate a multiple option select box I have
 run across so many errors that it's beyond belief... such nonsense as
 select for select or select=select ( think this is right, but then
 who knows?)

I know.  So does the HTML recommendation which states that it is a
boolean attribute, meaning it is stated (on/boolean 1) or it isn't
(off/boolean 0) in the HTML context.  So while other variations may
work, this is correct:

For multiple select:
SELECT multiple name=component-select

--or--

For single select:
SELECT name=component-select


  other variations; then theres in_array() that has
 explanations about as clear as a cesspool - the way it's explained is
 not at all clear, -- and somebody did an in_array($tring, text) -
 which is reversed... don't these idiots read what they are putting up on
 the internet?
 And some of you wonder why I ask stupid questions? Rare, indeed, is the
 clear explanation or demonstration. I get the impression that there are
 a lot of asholeys out there who learn the less than basic programming
 and then forget that even a ignoramus as I can be looking for rather
 complicated guidance. The Internet was a great promise, but god is is
 overbloated with floating intellectual excrement.
 Sorry, but ranting sometimes is good for the psyche. :o
 

Rather than copying and pasting from the Internet, learn the basics of
what you are doing and then use the documentation.  php.net has GREAT
docs and w3c.org is the answer for all of your HTML/CSS needs.

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

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



[PHP] Persistent data between two executions

2009-06-16 Thread James Colannino
Hey everyone,

Long time reader, not such a long time poster :-P (though I have posted
to the list occasionally in the past...)

Anyway, I have a general question for the list.  Basically, I need to
maintain persistent objects between page refreshes.  So, for example, if
while running a PHP script the first time I create an instance of class
foo, the next time the script is run (when the browser reloads the page)
I can again access that same instance of foo.

I know that there's no way to truly do that, since a script only runs
while generating output for the browser, but my question is, in the
group's opinion, what's the best way to mimic this sort of behavior
using temporary storage?  Should I be using temporary files?

I can think of at least a couple ways to do it, but I'd like to get some
opinions as to best practice techniques, which take both security and
relative efficiency into account.  I would want to make sure that data
isn't shared between multiple concurrent sessions, which would be a bad
thing for what I'm doing.  my oh-so-limited knowledge of PHP is shining
through, I think :)

Thanks so much!

James

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



RE: [PHP] Re: sloppiness stupidity

2009-06-16 Thread HallMarc Websites


 -Original Message-
 From: Shawn McKenzie [mailto:nos...@mckenzies.net]
 Sent: Tuesday, June 16, 2009 9:11 PM
 To: php-general@lists.php.net
 Subject: [PHP] Re: sloppiness  stupidity
 
 PJ wrote:
  I'm sorry, guys, but I am really getting po'd.
  The irresponsible sloppiness and stupidity is just getting to me.
  In my quest for a way to populate a multiple option select box I have
  run across so many errors that it's beyond belief... such nonsense as
  select for select or select=select ( think this is right, but then
  who knows?)
 
 I know.  So does the HTML recommendation which states that it is a
 boolean attribute, meaning it is stated (on/boolean 1) or it isn't
 (off/boolean 0) in the HTML context.  So while other variations may
 work, this is correct:
 
 For multiple select:
 SELECT multiple name=component-select
 
 --or--
 
 For single select:
 SELECT name=component-select
 
 
   other variations; then theres in_array() that has
  explanations about as clear as a cesspool - the way it's explained is
  not at all clear, -- and somebody did an in_array($tring, text) -
  which is reversed... don't these idiots read what they are putting up
 on
  the internet?
  And some of you wonder why I ask stupid questions? Rare, indeed, is
 the
  clear explanation or demonstration. I get the impression that there
 are
  a lot of asholeys out there who learn the less than basic programming
  and then forget that even a ignoramus as I can be looking for rather
  complicated guidance. The Internet was a great promise, but god is is
  overbloated with floating intellectual excrement.
  Sorry, but ranting sometimes is good for the psyche. :o
 
 
 Rather than copying and pasting from the Internet, learn the basics of
 what you are doing and then use the documentation.  php.net has GREAT
 docs and w3c.org is the answer for all of your HTML/CSS needs.
 
 --
 Thanks!
 -Shawn
 http://www.spidean.com
 

Wow. Leave the list for a few days and miss all the excitement. 

There are also a lot of good books out there to learn from. Taking a few 
classes and actually earning a degree wouldn't kill you either.

[Marc Hall - HallMarc Websites - http://www.hallmarcwebsites.com 610.446.3346]



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



Re: [PHP] Persistent data between two executions

2009-06-16 Thread Martin Scotta
You can use $_SESSION to store the object, and serialize to convert to
string and reverse

http://ar2.php.net/manual/en/language.oop.serialization.php

// file one.php
require 'user.php';
$user = new User();
$_SESSION[ 'user' ] = serialize( $user );

// file two.php
require 'user.php';   // the class needs to be declared
$user = unserialize( $_SESSION[ 'user' ] );

I think this is the cleanest way to do, but no the best performant.
If you need performance you can use the interface serializable
http://ar2.php.net/manual/en/class.serializable.php


If you need a resources (like a db connection) you can implement __sleep and
__wakeup in your class
http://ar2.php.net/manual/en/language.oop.magic-functions.php



On Wed, Jun 17, 2009 at 12:11 AM, James Colannino ja...@colannino.orgwrote:

 Hey everyone,

 Long time reader, not such a long time poster :-P (though I have posted
 to the list occasionally in the past...)

 Anyway, I have a general question for the list.  Basically, I need to
 maintain persistent objects between page refreshes.  So, for example, if
 while running a PHP script the first time I create an instance of class
 foo, the next time the script is run (when the browser reloads the page)
 I can again access that same instance of foo.

 I know that there's no way to truly do that, since a script only runs
 while generating output for the browser, but my question is, in the
 group's opinion, what's the best way to mimic this sort of behavior
 using temporary storage?  Should I be using temporary files?

 I can think of at least a couple ways to do it, but I'd like to get some
 opinions as to best practice techniques, which take both security and
 relative efficiency into account.  I would want to make sure that data
 isn't shared between multiple concurrent sessions, which would be a bad
 thing for what I'm doing.  my oh-so-limited knowledge of PHP is shining
 through, I think :)

 Thanks so much!

 James

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




-- 
Martin Scotta


Re: [PHP] populate form input option dropdown box from existing data

2009-06-16 Thread Ashley Sheridan
On Tue, 2009-06-16 at 20:46 -0400, PJ wrote:
 Ashley Sheridan wrote:
  On Tue, 2009-06-16 at 18:19 -0400, PJ wrote:

  Ashley Sheridan wrote:
  
  On Tue, 2009-06-16 at 15:48 -0400, PJ wrote:


  jenai tomaka wrote:
  
  
  You can try like this,
 
  $row = stored data;
   
  and write the options like this
  option value=id (id == $row ? selected : ) /option
 
 
  Yuri Yarlei.
 
  http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8


  Yuri, I'm still wet behind the ears on this so I don't quite
  understand what you mean by stored data ;  and what does the id
  (id==$row?selected:) mean?
  I get the idea that this might be translated into something in the code
  I have dreamed up - further down.
 
  echo option value=, $row['id'], , $row['category'], /optionbr 
  /;
  I suppose that I must add an if clause to insert the selected option for
  the categories that are relevant...
 
 
  Gentlemen,
  I have been diligently studying all this and have just returned my
  attention to the list, so I've read the replies/inputs and now comment:
 
  BTW, I had some problems with the multiple statement - it does not take
  any parameters; it must simply be stated multiple without quotes.
 
  Now, I was happy to learn that it is simpler to populate the insert new
  books page dynamically from the db. Much shorter  neater.
  It looks to me like the best solution for the edit page is close to what
  Yuri suggests.
  Since the edit page is very similar to the insert new books page, I
  merely need to populate the Select options box slightly differently.
  This is the code to populate the insert page:
  select name=categoriesIN[] multiple size=8
  ?php
  $sql = SELECT * FROM categories; 
if ( ( $results = mysql_query($sql, $db) ) !== false ) {
  while ( $row = mysql_fetch_assoc($results) ) {
  echo option value=, $row['id'], , $row['category'],
  /optionbr /;
  }
  }
  ?
  /select
 
  The problem nowis to find a way to add a conditional clause above that
  will insert the option=selected in the output.
  The input for this comes from:
  // do categories
  $sql = SELECT id, category FROM categories, book_categories
  WHERE book_categories.bookID = $idIN 
  book_categories.categories_id = categories.id;;
  if ( ( $results = mysql_query($sql, $db) ) !== false ) {
  while ( $row = mysql_fetch_assoc($results) ) {
  echo$row['id'], br /;
  }
  }
 
  This may return any number of category ids so the problem is to figure
  out a way to pass the ids from the above code to the right ids in the
  first code above.
  How  what do I search to match the two ids?
 
  -- 
  Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
  -
  Phil Jourdan --- p...@ptahhotep.com
 http://www.ptahhotep.com
 http://www.chiccantine.com/andypantry.php
 
 
  
  
  option value=id (id == $row ? selected : ) /option is
  pretty bad HTML, as attributes should always have a value. Personally, I
  do something like this as it tends not to confuse the code too much
 
  $selected = ($id == $row)?'selected=selected':'';
  print option value=\$id\ $selected /option;


  I was unable to get any of the suggestions to work, except in_array().
  However, the selected item refuses to become highlighted.
  code:
  select name=categoriesIN[] multiple size=8
  ?php
  $sql = SELECT * FROM categories;
  //$selected = ($id == $row)?'selected=selected':'';
if ( ( $results = mysql_query($sql, $db) ) !== false ) {
  while ( $row = mysql_fetch_assoc($results) ) {
  if (in_array($row['id'], $ccc)) {
echo option value=, $row['id'],  selected ,
  $row['category'], /optionbr /;
}
else echo option value=, $row['id'], ,
  $row['category'], /optionbr /;
  }
  }
  ?
  /select
  I can't find anything that explains why the selected item is not
  highlighted.
 
  -- 
  Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
  -
  Phil Jourdan --- p...@ptahhotep.com
 http://www.ptahhotep.com
 http://www.chiccantine.com/andypantry.php
 
  
  Have you actually looked at the html this produces to see if any of the
  elements are being marked with the selected=selected attribute?
 
  Thanks
  Ash
  www.ashleysheridan.co.uk

 I just cannot find a way to pass the selected fields to the options script.
 Even if I add the selected to all the fields, they show up in the source
 code but the fields are still not highlighted.
 There has to be a way to get this right??? :'(
 
 -- 
 Hervé Kempf: Pour sauver la planète, sortez du capitalisme.
 -
 Phil Jourdan --- 

Re: [PHP] Persistent data between two executions

2009-06-16 Thread James Colannino
Martin Scotta wrote:
 You can use $_SESSION to store the object, and serialize to convert to
 string and reverse

I like that idea.  I think I may end up going that route.

I have one question.  This is VERY hypothetical, and mostly just to
satisfy a curiosity, but let's assume that you write an application that
supports a few hundred users, each of which happen to be logged on at
the same time.

Assuming that serialization/unserialization happens frequently in the
application, how severely will that impact performance?  I'd imagine
quite a bit, since you're reading/writing a lot from disk, which is
inherently slow.

I suppose one interesting way to alleviate this problem on a per-machine
basis would be to implement /tmp in a RAM disk, so that session data is
effectively written to and read from memory instead of to and from the disk.

I suppose the best solution would be to design things such that as
little data as possible is serialized between page refreshes.

James

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