php-general Digest 3 Dec 2008 19:06:19 -0000 Issue 5824

Topics (messages 284035 through 284063):

SELECT into array of arrays
        284035 by: Andrej Kastrin
        284040 by: Yeti
        284042 by: Yeti
        284057 by: Andrej Kastrin
        284059 by: ceo.l-i-e.com
        284060 by: Yeti

Re: Accessing the 'media' attribute in php
        284036 by: Maciek Sokolewicz
        284037 by: Clancy
        284038 by: Yeti
        284041 by: Ashley Sheridan
        284046 by: Clancy
        284048 by: Colin Guthrie
        284051 by: Michael Kubler
        284055 by: ceo.l-i-e.com

imap4 search criterias
        284039 by: Ergün Koray
        284049 by: Richard Heyes
        284054 by: Ergün Koray
        284058 by: ceo.l-i-e.com

Re: Objects and Arrays Conversion
        284043 by: Nathan Nobbe

adding key-> value pair to an array
        284044 by: Aniketto
        284045 by: Aniketto
        284047 by: Yeti
        284061 by: Jim Lucas
        284062 by: Jim Lucas
        284063 by: Nathan Rixham

Picture downloading in IE
        284050 by: Sándor Tamás (HostWare Kft.)
        284052 by: Sándor Tamás (HostWare Kft.)
        284053 by: mike

Re: How to type arguments
        284056 by: ceo.l-i-e.com

Administrivia:

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

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

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


----------------------------------------------------------------------
--- Begin Message ---
Dear all,

I have a MySQL table 'test' which includes two columns: 'study' and 'symbol':

study symbol
a2008 A
a2008 B
a2008 C
a2008 D
b2005 A
b2005 B
b2005 E


Using POST variable I passed 'study' values into $myArray:

// $myArray is variable length; used only two values in example
$myArray = array("a2008","b2005");


Then I try to produce the following structure (array of arrays):

$combinedArray = array(array('A','B','C','D'),array('A','B','E'));


Below is my php script. In the present solution the $combinedArray includes only 'symbol' values for last iteration (where $myArray = "b2005").

How should I proceed? Thanks in advance for any suggestions.

Best, Andrej



$combinedArray = array();
for ($i=0;$i<count($myArray);$i++) {

$sql = "SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]')";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0) {
    while ($myrow = mysql_fetch_array($result)) {
        $combinedArray[] = $myrow['symbol'];
    }
}
}

--- End Message ---
--- Begin Message ---
> How should I proceed? Thanks in advance for any suggestions.

Since you are looping through the result already, why not do it this way ..

$combinedArray = array();
for ($i=0;$i<count($myArray);$i++) {

$sql = "SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]')";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0) {
   while ($myrow = mysql_fetch_array($result)) {
       if (in_array($myrow['study'], $myArray))
$combinedArray[$myrow['study']][] = $myrow['symbol'];
   }
}
}

You should get an array like this ...
array("b2008" => array("A", "B", "C", "D"), "b2005" => array("A", "B", "E"))

--- End Message ---
--- Begin Message ---
Correcting myself now ..

$myArray = array('b2005', 'b2008');
$sql = "SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]')";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0) {
  while ($myrow = mysql_fetch_array($result)) {
      if (in_array($myrow['study'], $myArray))
$combinedArray[$myrow['study']][] = $myrow['symbol'];
  }
}

Forgot to get rid of the first for loop

--- End Message ---
--- Begin Message ---
Thanks Yeti, it works.

Best, Andrej

Yeti wrote:
Correcting myself now ..

$myArray = array('b2005', 'b2008');
$sql = "SELECT study,symbol FROM test WHERE study IN ('$myArray[$i]')";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0) {
  while ($myrow = mysql_fetch_array($result)) {
      if (in_array($myrow['study'], $myArray))
$combinedArray[$myrow['study']][] = $myrow['symbol'];
  }
}

Forgot to get rid of the first for loop

--- End Message ---
--- Begin Message ---
I actually would do more like:



$myArray[$study][$symbol] = true;



No need to call in_array.



Probably won't matter, really, but it's a good practice for when you end up 
doing the same kind of code for an array with thousands of elements.



--- End Message ---
--- Begin Message ---
And yet another thing i have overseen in my statement ..
If you remove the first for loop, also change the sql query. But I'm
sure you saw that already

NEW QUERY:
$sql = "SELECT study,symbol FROM test WHERE study IN ('".implode(', ',
$myArray)."')";

--- End Message ---
--- Begin Message ---
Clancy wrote:
Oh?
Unfortunately I have had great difficulty trying to find out how
things really work, as all the books I have seen are recipe books,
which tell you how to achieve particular results, but not what is
going on behind the scenes.  I had assumed that when you hit the
'print' button the browser sent a new request to the server, with a
different set of parameters, but I gather from your reply that the
browser issues the new (printer) page without reference to the server.
Is this what actually happens?

If so I fear I will have to work out how to achieve the results I want
with CSS styles.  It would have been far simpler if I could have done
it in php.

Thank you for your help.

On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] ("German Geek")
wrote:

PHP is a server side language...

On Wed, Dec 3, 2008 at 2:16 PM, Clancy <[EMAIL PROTECTED]> wrote:

Is it possible to access the 'media' attribute from php, so (for
example) you can tailor a page for printing?


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



Rule #1 on this list: don't top post.

That is how it works indeed, you request the page, the server runs the php script, collects the output and sends it to the browser. You view the page in the browser, press print, the browser sends the page data to the printer spooler which sends it to the printer. No PHP involved after it was sent from the server back to the browser. You basically have 2 options now:
1. change the looks trough a different stylesheet (the pretty option)
2. add a "print" button/link on your page which, when clicked, will redirect to a new page in "print format". Then use the javascript print function to call up the browser's print dialog.

As for books, most PHP books aren't recipe books, so you've been looking at the wrong ones :) I can recommend O'Reilly's books, they're pretty good. Especially Programming PHP [1]. But that's just my general liking of those books ;)

- Tul

[1] http://oreilly.com/catalog/9780596006815/

--- End Message ---
--- Begin Message ---
On Wed, 3 Dec 2008 15:28:17 +1300, [EMAIL PROTECTED] ("German Geek")
wrote:

>You can do things on the client side with Javascript ;) Sorry, what was the
>result you are after?

I have enough trouble getting my rather ancient brain around PHP, and
was hoping that I could avoid getting involved with JavaScript.
However it seems that it, or CSS, are the only possibilities for this
case.

Bother!

--- End Message ---
--- Begin Message ---
> I have enough trouble getting my rather ancient brain around PHP, and
> was hoping that I could avoid getting involved with JavaScript.
> However it seems that it, or CSS, are the only possibilities for this
> case.

If I understood you correctly what you want is to change the style of
the page when the user is printing it.
As others mentioned before all you would have to do would be adding a
second style sheet for that purpose.

EXAMPLE:
<link rel="stylesheet" media="screen" href="/styles/main.css" type="text/css" />
<link rel="stylesheet" media="print" href="/styles/print.css" type="text/css" />

That would be all. Now if you want the user to have some kind of
preview when clickin on a "print the page" button or link
you need either JavaScript or PHP. The easiest way I could think of
would be using the same print style sheet.

For JavaScript have a look at this page ...
http://www.quirksmode.org/dom/changess.html

I think it should work in most modern browsers. Still doing it with
PHP will work in every browser, but requires the page to reload ...
For PHP have a look at this page ...
http://www.maratz.com/blog/archives/2004/09/21/10-minutes-to-printer-friendly-page/#printQuery

//A yeti

--- End Message ---
--- Begin Message ---
On Wed, 2008-12-03 at 08:00 +0100, Maciek Sokolewicz wrote:
> Clancy wrote:
> > Oh? 
> > 
> > Unfortunately I have had great difficulty trying to find out how
> > things really work, as all the books I have seen are recipe books,
> > which tell you how to achieve particular results, but not what is
> > going on behind the scenes.  I had assumed that when you hit the
> > 'print' button the browser sent a new request to the server, with a
> > different set of parameters, but I gather from your reply that the
> > browser issues the new (printer) page without reference to the server.
> > Is this what actually happens?
> > 
> > If so I fear I will have to work out how to achieve the results I want
> > with CSS styles.  It would have been far simpler if I could have done
> > it in php.
> > 
> > Thank you for your help.
> > 
> > On Wed, 3 Dec 2008 14:34:20 +1300, [EMAIL PROTECTED] ("German Geek")
> > wrote:
> > 
> >> PHP is a server side language...
> >>
> >> On Wed, Dec 3, 2008 at 2:16 PM, Clancy <[EMAIL PROTECTED]> wrote:
> >>
> >>> Is it possible to access the 'media' attribute from php, so (for
> >>> example) you can tailor a page for printing?
> >>>
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>>
> 
> Rule #1 on this list: don't top post.
> 
> That is how it works indeed, you request the page, the server runs the 
> php script, collects the output and sends it to the browser. You view 
> the page in the browser, press print, the browser sends the page data to 
> the printer spooler which sends it to the printer. No PHP involved after 
> it was sent from the server back to the browser. You basically have 2 
> options now:
> 1. change the looks trough a different stylesheet (the pretty option)
> 2. add a "print" button/link on your page which, when clicked, will 
> redirect to a new page in "print format". Then use the javascript print 
> function to call up the browser's print dialog.
> 
> As for books, most PHP books aren't recipe books, so you've been looking 
> at the wrong ones :) I can recommend O'Reilly's books, they're pretty 
> good. Especially Programming PHP [1]. But that's just my general liking 
> of those books ;)
> 
> - Tul
> 
> [1] http://oreilly.com/catalog/9780596006815/
> 
Go with what Yeti said. The browser will automatically pick the right
stylesheet when the user presses the print button or you issue a
window.print() from Javascript. Whatever you do, don't have a separate
page for "print view". This is one of those things that some bright
spark thought to do on a site at work, and the site in question was
already a couple hundred HTML pages, so he effectively doubled that
figure. It makes your work harder in the long run if you need to update
it at any time, and with the media="print" attribute set for the extra
stylesheet, it's automatically selected anyways.

On an aside, Opera has a neat option that lets you select from all the
stylesheets a page has available, which will make it easier when you're
developing the stylesheet rather than having to keep clicking print
preview in your browser!


Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
On Wed, 03 Dec 2008 08:15:14 +0000, [EMAIL PROTECTED] (Ashley
Sheridan) wrote:

>Go with what Yeti said. The browser will automatically pick the right
>stylesheet when the user presses the print button or you issue a
>window.print() from Javascript. Whatever you do, don't have a separate
>page for "print view". This is one of those things that some bright
>spark thought to do on a site at work, and the site in question was
>already a couple hundred HTML pages, so he effectively doubled that
>figure. It makes your work harder in the long run if you need to update
>it at any time, and with the media="print" attribute set for the extra
>stylesheet, it's automatically selected anyways.
>
>On an aside, Opera has a neat option that lets you select from all the
>stylesheets a page has available, which will make it easier when you're
>developing the stylesheet rather than having to keep clicking print
>preview in your browser!

Thank you to everyone who has replied on this. While there are
reasonably good books on the individual tools (PHP, JavaScript, etc)
very few go into how they all interact, and this was the subject of my
confusion.  Maciek's succinct description has made it clear why my
original request could never be implemented, so I will have to use CSS
to achieve the results I want.

This is not THAT bad, but CSS was clearly not designed by a
programmer, and to my mind seems to have a very convoluted logic, so I
prefer to avoid using it if I can.

And thank you for the tip about Opera. That feature sounds as if it
could be very useful!

--- End Message ---
--- Begin Message ---
'Twas brillig, and Ashley Sheridan at 03/12/08 08:15 did gyre and gimble:
Whatever you do, don't have a separate
page for "print view". This is one of those things that some bright
spark thought to do on a site at work, and the site in question was
already a couple hundred HTML pages, so he effectively doubled that
figure. It makes your work harder in the long run if you need to update
it at any time, and with the media="print" attribute set for the extra
stylesheet, it's automatically selected anyways.

While I don't want to disagree with the print media option (it's my preferred route), depending on your application/use case etc, having a separate print layout could make sense.

Say you have a content management system that displays an "entry" over several small pages. If you want to print out details of that "entry" it may make sense to combine the salient details from all the mini-pages into one "printable" page.

If your application is designed well, then this approach certainly doesn't double your number of "pages" (from a maintenance perspective). If you have a 1000 "entries" each with 5 mini-pages and you add a print version you are changing the number from 5 to 6, not 5000 to 6000.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


--- End Message ---
--- Begin Message ---
A couple of sites about making CSS print stylesheets.

http://www.alistapart.com/articles/goingtoprint/
http://www.webdesignschoolreview.com/css-printing.html

I'd send you links to more, but my Internet connection is shaped, and it's too slow to look through many more.

Michael Kubler
*G*rey *P*hoenix *P*roductions <http://www.greyphoenix.biz>



Clancy wrote:
On Wed, 3 Dec 2008 15:28:17 +1300, [EMAIL PROTECTED] ("German Geek")
wrote:

You can do things on the client side with Javascript ;) Sorry, what was the
result you are after?

I have enough trouble getting my rather ancient brain around PHP, and
was hoping that I could avoid getting involved with JavaScript.
However it seems that it, or CSS, are the only possibilities for this
case.

Bother!

--- End Message ---
--- Begin Message ---
> but I gather from your reply that the browser issues the new (printer)

> page without reference to the server.

> Is this what actually happens?



Yes, this is what actually happens for the browser "print" button.



You could do something like a "Printer Friendly" button to generate a PDF on 
the fly or somesuch, and POST back all the data you need to generate a nice PDF 
of the page.



Example:

http://l-i-e.com/resume.htm

(Source code link at the bottom of the page)



Reference material:

http://php.net/libpdf



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

I have a Fedora Core 9 system with php 5.2.5 and imap enabled.
A little program that uses imap_search results in this error. Does the
current php version support imap4 search criterias ?

Thanks for your help.

Here is the little program :
<?php
$mbox = imap_open("{192.6.10.1:143/service=imap}INBOX",
"[EMAIL PROTECTED]", "***", CL_EXPUNGE)
     or die("can't connect: " . imap_last_error());

$MC = imap_check($mbox);
$searchResults = imap_search($mbox, "SENTSINCE \"02 Dec 2008\"", SE_UID) ;
if(!empty($searchResults)) {
        echo "Not Empty<br/>" ;
        $concatResults = implode(",", $searchResults);
        // Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,$concatResults, SE_NOPREFETCH+SE_UID);
foreach ($result as $overview) {
    echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from}
    {$overview->subject}<br />\n";
}
        
}
else
{
        echo "Empty " . imap_last_error() ;
}

imap_close($mbox);
?

Here is the result :

Unknown search criterion: SENTSINCE

-- 
Ergün Koray
bb, vm, mu, xg

--- End Message ---
--- Begin Message ---
> I have a Fedora Core 9 system with php 5.2.5 and imap enabled.
> A little program that uses imap_search results in this error. Does the
> current php version support imap4 search criterias ?

It does, and has done for a while. I used it my Vwebmail application
(which I no longer have I'm afraid). But try the manual:
http://uk2.php.net/imap_search

-- 
Richard Heyes

HTML5 Graphing for FF, Chrome, Opera and Safari:
http://www.rgraph.org (Updated November 29th)

--- End Message ---
--- Begin Message ---
Thanks for the quick reply,

There is no SENTSINCE keyword in the critera parameter section, so I
believe that no SENTSINCE queries can be performed againts the server.
The problem with the SINCE keyword is that it returns the wrong
results.



On Wed, Dec 3, 2008 at 12:07 PM, Richard Heyes <[EMAIL PROTECTED]> wrote:
>> I have a Fedora Core 9 system with php 5.2.5 and imap enabled.
>> A little program that uses imap_search results in this error. Does the
>> current php version support imap4 search criterias ?
>
> It does, and has done for a while. I used it my Vwebmail application
> (which I no longer have I'm afraid). But try the manual:
> http://uk2.php.net/imap_search
>
> --
> Richard Heyes
>
> HTML5 Graphing for FF, Chrome, Opera and Safari:
> http://www.rgraph.org (Updated November 29th)
>



-- 
Ergün Koray
bb, vm, mu, xg

--- End Message ---
--- Begin Message ---
As I recall, there needs to be a \SENTSINCE instead of just SENTSINCE, and the 
PHP online manual ended up stripping out the \ business...



Or maybe that was in some kind of "flags" somewhere else...



Check the user contributed notes -- Those are invaluable for "what can go 
wrong" type of insight.



--- End Message ---
--- Begin Message ---
On Tue, Dec 2, 2008 at 7:48 PM, Micah Gersten <[EMAIL PROTECTED]> wrote:

> VamVan wrote:
> > Hello All,
> >
> > I was stuck with this issue. So just felt the need to reach out to other
> > strugglers.
> > May be people might enjoy this:
> >
> > Here is the code for object to array and array to object conversion:
> >
> > function object_2_array($data)
> > {
> >     if(is_array($data) || is_object($data))
> >     {
> >         $result = array();
> >         foreach ($data as $key => $value)
> >         {
> >             $result[$key] = object_2_array($value);
> >         }
> >         return $result;
> >     }
> >     return $data;
> > }
> >
> > function array_2_object($array) {
> >  $object = new stdClass();
> >  if (is_array($array) && count($array) > 0) {
> >     foreach ($array as $name=>$value) {
> >        $name = strtolower(trim($name));
> >        if (!empty($name)) {
> >           $object->$name = $value;
> >        }
> >     }
> >  }
> >  return $object;
> > }
> >
> > have fun !!!!!
> >
> > Thanks
> >
> >
> ...
> As for the object to array, the same thing applies:
> http://us2.php.net/manual/en/language.types.array.php
>
> $array = (array) $object;


not quite, take a look at VamVan's object_2_array(), its recursive.  a
simple type-cast will only alter the outermost layer of the $object in your
example above.  im not sure, but im assuming VamVan may have meant to make
array_2_object() recursive as well ??  that would be more consistent anyway
imo..

heres a simple script to illustrate the shallow nature of type-casting

<?php
$arr = array(
        'b' => array(
                'c' => array(
                        'd'
                )
        )
);

$obj = new stdClass();
$obj->b = new stdClass();
$obj->b->c = new stdClass();
$obj->b->c->d = new stdClass();

var_dump((array)$obj);
var_dump((object)$arr);
?>

results in

phdelnnobbe:~ nnobbe$ php arrayToObject.php
array(1) {
  ["b"]=>
  object(stdClass)#2 (1) {
    ["c"]=>
    object(stdClass)#3 (1) {
      ["d"]=>
      object(stdClass)#4 (0) {
      }
    }
  }
}
object(stdClass)#5 (1) {
  ["b"]=>
  array(1) {
    ["c"]=>
    array(1) {
      [0]=>
      string(1) "d"
    }
  }
}


> Not sure if these are PHP 5 only or not.


the manual should say.

-nathan

--- End Message ---
--- Begin Message ---
Hi all,
Can anybody tell me how can I add key->value pair in an array.
My code is as follows

 $criteria = array();
 $criteria['mail_subject'] = $form->subject->getValue();
 $criteria['delivery_user_name'] = $form->delivery_user_name->getValue();
 $criteria['start_date'] = $form->start_date->getValue();
 $criteria['end_date'] = $form->end_date->getValue();
 $criteria['group'] = $form->group->getValue();
                
 // get table data from database
 $rowset = $mailDelivery->findDeliveryMailData($criteria);

//convert rowset into an array
 $mailDataArray = $rowset->toArray();
                        

 if(count($mailDataArray) != 0){
        foreach($mailDataArray as $row){                                        
                $condition['mail_delivery_id'] = $row->id;
                $browseCount = $mailDeliveryDetail->findBrowseCount($condition);
                $totalCount = $mailDeliveryDetail->findTotalCount($condition);
              //for each row I want to add percentage as new key->value pair
                         // but it gives error 'Undefined variable:
percentage'
                $row->$percentage = ($browseCount / $totalCount ) * 100;        
        
 }
 }


Please somebody tell me how to achieve this.
Thanks in advance.
Aniket
-- 
View this message in context: 
http://www.nabble.com/adding-key-%3E-value-pair-to-an-array-tp20809114p20809114.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
Hi all,
Can anybody tell me how can I add key->value pair in an array.
My code is as follows

 $criteria = array();
 $criteria['mail_subject'] = $form->subject->getValue();
 $criteria['delivery_user_name'] = $form->delivery_user_name->getValue();
 $criteria['start_date'] = $form->start_date->getValue();
 $criteria['end_date'] = $form->end_date->getValue();
 $criteria['group'] = $form->group->getValue();
                
 // get table data from database
 $rowset = $mailDelivery->findDeliveryMailData($criteria);

//convert rowset into an array
 $mailDataArray = $rowset->toArray();
                        

 if(count($mailDataArray) != 0){
        foreach($mailDataArray as $row){                                        
                $condition['mail_delivery_id'] = $row->id;
                $browseCount = $mailDeliveryDetail->findBrowseCount($condition);
                $totalCount = $mailDeliveryDetail->findTotalCount($condition);
              //for each row I want to add percentage as new key->value pair
                         // but it gives error 'Undefined variable:
percentage'
                $row->$percentage = ($browseCount / $totalCount ) * 100;        
        
 }
 }


Please somebody tell me how to achieve this.
Thanks in advance.
Aniket
-- 
View this message in context: 
http://www.nabble.com/adding-key-%3E-value-pair-to-an-array-tp20809115p20809115.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
> //for each row I want to add percentage as new key->value pair
>                         // but it gives error 'Undefined variable:
> percentage'
>                $row->$percentage = ($browseCount / $totalCount ) * 100;

Obviously you get the error because $percentage is not defined ..

I did not fully understand what you wanted.

Here is a list of what should work ...

#Set a variable percentage in $row
$row->percentage = ($browseCount / $totalCount ) * 100;

#Set a variable with name $percentage in $row
$percentage = ($browseCount / $totalCount ) * 100;
$row->$percentage = $percentage;

--- End Message ---
--- Begin Message ---
Yeti wrote:
>> //for each row I want to add percentage as new key->value pair
>>                         // but it gives error 'Undefined variable:
>> percentage'
>>                $row->$percentage = ($browseCount / $totalCount ) * 100;
> 
> Obviously you get the error because $percentage is not defined ..
> 
> I did not fully understand what you wanted.
> 
> Here is a list of what should work ...
> 
> #Set a variable percentage in $row
> $row->percentage = ($browseCount / $totalCount ) * 100;
> 
> #Set a variable with name $percentage in $row
> $percentage = ($browseCount / $totalCount ) * 100;
> $row->$percentage = $percentage;
> 

I don't think the above will work either, afaik php doesn't allow you to have 
variable names start with numbers.  Also, there is a high possibility
that $percentage would end up being a float.

-- 
Jim Lucas

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

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
Aniketto wrote:
> Hi all,
> Can anybody tell me how can I add key->value pair in an array.
> My code is as follows
> 
>  $criteria = array();
>  $criteria['mail_subject'] = $form->subject->getValue();
>  $criteria['delivery_user_name'] = $form->delivery_user_name->getValue();
>  $criteria['start_date'] = $form->start_date->getValue();
>  $criteria['end_date'] = $form->end_date->getValue();
>  $criteria['group'] = $form->group->getValue();
>               
>  // get table data from database
>  $rowset = $mailDelivery->findDeliveryMailData($criteria);
> 
> //convert rowset into an array
>  $mailDataArray = $rowset->toArray();
>                       

if you do a print_r() right here on $mailDataArray, what does it look like?

> 
>  if(count($mailDataArray) != 0){
>       foreach($mailDataArray as $row){                                        
>               $condition['mail_delivery_id'] = $row->id;
>               $browseCount = $mailDeliveryDetail->findBrowseCount($condition);
>               $totalCount = $mailDeliveryDetail->findTotalCount($condition);
>               //for each row I want to add percentage as new key->value pair
>                          // but it gives error 'Undefined variable:
> percentage'
>               $row->$percentage = ($browseCount / $totalCount ) * 100;        
>         

Were you intending to just say $row->percentage  instead of calling $percentage?

>  }
>  }
> 
> 
> Please somebody tell me how to achieve this.
> Thanks in advance.
> Aniket


-- 
Jim Lucas

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

Twelfth Night, Act II, Scene V
    by William Shakespeare

--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
I don't think the above will work either, afaik php doesn't allow you to have variable names start with numbers.

well debatable..

#################
$12 = 'value';
Parsing Error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$'

#################
$varname = 12;
$$varname = 'sentence';
echo $$varname;
//echos sentence

#################
${12} = 'some string here';
echo ${12};
//echos some string here

################
//you can get really stupid with this..
${false} = 'some string here';
echo ${''};
//echos some string here

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

I have a strange error / misfunction with PHP header and IE7.

I render a JPG from a database BLOB to show it on a page.
In Firefox, when the user clicks on the image, and selects "Save image as... ", 
(s)he can download it in JPG format.
But when a user in IE7 does the same, (s)he only can getit in BMP.

The header I sent is the same both case: 

header('Content-Type: image/pjpeg');

I tried to set Content-Disposition to "inline" or "attachment", set filename to 
different values, but get the same result.

Now all I can say is "HEEEEEELP" :)

Thanks,
SanTa

--- End Message ---
--- Begin Message ---
I don't think, because it happens on different machines, with different users. 
(one of them is a fresh install)

SanTa
  ----- Original Message ----- 
  From: Ramesh Thiruchelvam 
  To: Sándor Tamás (HostWare Kft. ) 
  Sent: Wednesday, December 03, 2008 12:05 PM
  Subject: Re: [PHP] Picture downloading in IE


  Hi Santa,

  It seems to be a problem in IE when damaged activex or a java object is in 
the cache. Try clearing your temporary internet files and see.

  http://support.microsoft.com/kb/810978

  Kr,
  Ramesh


  On Wed, Dec 3, 2008 at 4:20 PM, Sándor Tamás (HostWare Kft. ) <[EMAIL 
PROTECTED]> wrote:

    Hi,

    I have a strange error / misfunction with PHP header and IE7.

    I render a JPG from a database BLOB to show it on a page.
    In Firefox, when the user clicks on the image, and selects "Save image 
as... ", (s)he can download it in JPG format.
    But when a user in IE7 does the same, (s)he only can getit in BMP.

    The header I sent is the same both case:

    header('Content-Type: image/pjpeg');

    I tried to set Content-Disposition to "inline" or "attachment", set 
filename to different values, but get the same result.

    Now all I can say is "HEEEEEELP" :)

    Thanks,
    SanTa


--- End Message ---
--- Begin Message ---
I've seen this issue on a normally healthy machine. I think it's a
memory issue, or IE just corrupting itself sometimes. I don't change
anything and it seems to go away (probably fresh browser session)

Although I am sure invalid/confusing headers won't help.

On Wed, Dec 3, 2008 at 3:08 AM, Sándor Tamás (HostWare Kft. )
<[EMAIL PROTECTED]> wrote:
> I don't think, because it happens on different machines, with different 
> users. (one of them is a fresh install)
>
> SanTa
>  ----- Original Message -----
>  From: Ramesh Thiruchelvam
>  To: Sándor Tamás (HostWare Kft. )
>  Sent: Wednesday, December 03, 2008 12:05 PM
>  Subject: Re: [PHP] Picture downloading in IE
>
>
>  Hi Santa,
>
>  It seems to be a problem in IE when damaged activex or a java object is in 
> the cache. Try clearing your temporary internet files and see.
>
>  http://support.microsoft.com/kb/810978
>
>  Kr,
>  Ramesh
>
>
>  On Wed, Dec 3, 2008 at 4:20 PM, Sándor Tamás (HostWare Kft. ) <[EMAIL 
> PROTECTED]> wrote:
>
>    Hi,
>
>    I have a strange error / misfunction with PHP header and IE7.
>
>    I render a JPG from a database BLOB to show it on a page.
>    In Firefox, when the user clicks on the image, and selects "Save image 
> as... ", (s)he can download it in JPG format.
>    But when a user in IE7 does the same, (s)he only can getit in BMP.
>
>    The header I sent is the same both case:
>
>    header('Content-Type: image/pjpeg');
>
>    I tried to set Content-Disposition to "inline" or "attachment", set 
> filename to different values, but get the same result.
>
>    Now all I can say is "HEEEEEELP" :)
>
>    Thanks,
>    SanTa
>
>

--- End Message ---
--- Begin Message ---
I'm surprised nobody mentioned:

http://php.net/assert

in this thread yet.



Perhaps I missed it?



You should really consider doing this:



1) At the outer API layer, do a typecast (possibly with preg_match first) to 
convert the input data to acceptable form.



2) For inner API layer[s], sprinkle "assert" calls as needed to make sure 
during dev/testing that the outer layer is doing it right.



In PROD, the assert can turn into a no-op, with no performance penalty, as I 
understand it.



Disclosure:

I've never worked on a project organized enough to actually do this properly.  
Sigh.

:-)



--- End Message ---

Reply via email to