php-general Digest 9 May 2008 09:40:50 -0000 Issue 5449

Topics (messages 274039 through 274055):

Recursion... Sort of...
        274039 by: Matt Neimeyer
        274040 by: Nathan Nobbe
        274044 by: Jim Lucas
        274045 by: David Otton
        274047 by: Nathan Nobbe
        274050 by: Stut

Re: Setting up a program that can be accessed by all domain on a server
        274041 by: Nathan Nobbe

Re: mysql query and maximum characters in sql statement
        274042 by: Chris

Re: Where to start!
        274043 by: Mark Weaver

Re: AI file and mapping with PHP
        274046 by: paragasu

Odd performance problem
        274048 by: Joeri Sebrechts
        274049 by: Robert Cummings

PHP/SOAP WDSL Restrictions
        274051 by: Paul van Brouwershaven
        274052 by: Paul van Brouwershaven

Re: Newbie - is there a function similar to the sql 'like' comparison operator?
        274053 by: Colin Guthrie

quick question
        274054 by: Merca, Ansta Ltd

Get array as string --Help
        274055 by: Shelley

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 ---
Is there a way to tell if a function has been called that has resulted
in a call to the same function?

We have an in-house CRM app that has a function that draws a tabbed
panel on a screen... BUT if there are sub-sub-tabbed panels we want to
invert the tab colors and panel colors...

So...

DrawSubTab($Set) - Black on White
   Content
   DrawSubTab($Set) - White on Black
      Content
      DrawSubTab($Set) - Black on White
         Content
      DrawSubTab($Set) - Black on White
         Content
         Etc...

I suppose I could rewrite EVERY call to the function with a recursion
count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE
commit... whereas if the function can determine itself... All that
said I can't think of a good way to do it without a bastardized global
variable that track "how deep" we are and there is something that
bothers me about that approach... Unless that really is the easiest
way.

Thanks in advance!

Matt

--- End Message ---
--- Begin Message ---
On Thu, May 8, 2008 at 3:48 PM, Matt Neimeyer <[EMAIL PROTECTED]> wrote:

> Is there a way to tell if a function has been called that has resulted
> in a call to the same function?
>
> We have an in-house CRM app that has a function that draws a tabbed
> panel on a screen... BUT if there are sub-sub-tabbed panels we want to
> invert the tab colors and panel colors...
>
> So...
>
> DrawSubTab($Set) - Black on White
>   Content
>   DrawSubTab($Set) - White on Black
>      Content
>      DrawSubTab($Set) - Black on White
>         Content
>      DrawSubTab($Set) - Black on White
>         Content
>         Etc...
>
> I suppose I could rewrite EVERY call to the function with a recursion
> count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE
> commit... whereas if the function can determine itself... All that
> said I can't think of a good way to do it without a bastardized global
> variable that track "how deep" we are and there is something that
> bothers me about that approach... Unless that really is the easiest
> way.


you dont need a global, you can have a variable that persists throughout the
request local only to the function itself using the static keyword.

function doStuff() {
  static $callCount;

  if(!isset($callCount))
   $callCount = 1;
  else
    $callCount++;

  /// do stuff w/ $callCount to potentially handle sub-tabs and stuff

  $callCount--;
}

-nathan

--- End Message ---
--- Begin Message ---
Nathan Nobbe wrote:
On Thu, May 8, 2008 at 3:48 PM, Matt Neimeyer <[EMAIL PROTECTED]> wrote:

Is there a way to tell if a function has been called that has resulted
in a call to the same function?

We have an in-house CRM app that has a function that draws a tabbed
panel on a screen... BUT if there are sub-sub-tabbed panels we want to
invert the tab colors and panel colors...

So...

DrawSubTab($Set) - Black on White
  Content
  DrawSubTab($Set) - White on Black
     Content
     DrawSubTab($Set) - Black on White
        Content
     DrawSubTab($Set) - Black on White
        Content
        Etc...

I suppose I could rewrite EVERY call to the function with a recursion
count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE
commit... whereas if the function can determine itself... All that
said I can't think of a good way to do it without a bastardized global
variable that track "how deep" we are and there is something that
bothers me about that approach... Unless that really is the easiest
way.


you dont need a global, you can have a variable that persists throughout the
request local only to the function itself using the static keyword.

function doStuff() {
  static $callCount;

  if(!isset($callCount))
   $callCount = 1;
  else
    $callCount++;

  /// do stuff w/ $callCount to potentially handle sub-tabs and stuff

  $callCount--;
}

-nathan


Look at the way he wants it to work. Your way would change alternate the color each time the function is called. I think the best/easiest way to keep track of depth will be by passing a variable in the function call itself.

--
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 ---
2008/5/8 Matt Neimeyer <[EMAIL PROTECTED]>:

> Is there a way to tell if a function has been called that has resulted
> in a call to the same function?

debug_backtrace()

Can't comment on performance, though. Its an inelegant solution.

> We have an in-house CRM app that has a function that draws a tabbed
> panel on a screen... BUT if there are sub-sub-tabbed panels we want to
> invert the tab colors and panel colors...
>
> So...
>
> DrawSubTab($Set) - Black on White
>   Content
>   DrawSubTab($Set) - White on Black
>      Content
>      DrawSubTab($Set) - Black on White
>         Content
>      DrawSubTab($Set) - Black on White
>         Content
>         Etc...

Nested? You may be able to do this in pure CSS, without keeping a
depth counter at all.

> I suppose I could rewrite EVERY call to the function with a recursion
> count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE
> commit... whereas if the function can determine itself... All that

It's an easy change.

function DrawSubTable($Set, $DepthCount = 0)
{
    [..]
    DrawSubTable($Set, $DepthCount + 1);
    [..]
}

By providing a default value, all the calls to DrawSubTable() can
remain unchanged. You just have to modify its own calls to itself.

--- End Message ---
--- Begin Message ---
On Thu, May 8, 2008 at 6:23 PM, Jim Lucas <[EMAIL PROTECTED]> wrote:

> Nathan Nobbe wrote:
>
>> On Thu, May 8, 2008 at 3:48 PM, Matt Neimeyer <[EMAIL PROTECTED]> wrote:
>>
>>  Is there a way to tell if a function has been called that has resulted
>>> in a call to the same function?
>>>
>>> We have an in-house CRM app that has a function that draws a tabbed
>>> panel on a screen... BUT if there are sub-sub-tabbed panels we want to
>>> invert the tab colors and panel colors...
>>>
>>> So...
>>>
>>> DrawSubTab($Set) - Black on White
>>>  Content
>>>  DrawSubTab($Set) - White on Black
>>>     Content
>>>     DrawSubTab($Set) - Black on White
>>>        Content
>>>     DrawSubTab($Set) - Black on White
>>>        Content
>>>        Etc...
>>>
>>> I suppose I could rewrite EVERY call to the function with a recursion
>>> count like DrawSubTab($Set,$DepthCount+1) but that would be a MASSIVE
>>> commit... whereas if the function can determine itself... All that
>>> said I can't think of a good way to do it without a bastardized global
>>> variable that track "how deep" we are and there is something that
>>> bothers me about that approach... Unless that really is the easiest
>>> way.
>>>
>>
>>
>> you dont need a global, you can have a variable that persists throughout
>> the
>> request local only to the function itself using the static keyword.
>>
>> function doStuff() {
>>  static $callCount;
>>
>>  if(!isset($callCount))
>>   $callCount = 1;
>>  else
>>    $callCount++;
>>
>>  /// do stuff w/ $callCount to potentially handle sub-tabs and stuff
>>
>>  $callCount--;
>> }
>>
>> -nathan
>>
>>
> Look at the way he wants it to work.  Your way would change alternate the
> color each time the function is called.  I think the best/easiest way to
> keep track of depth will be by passing a variable in the function call
> itself.


actually, i didnt supply the part where he does what he wants with the
depth.  i merely provided a way to track it without using a global
variable.  he could easily do something specific depending upon the depth
with what ive shown.

<?php
function doStuff() {
 static $callCount;

 if(!isset($callCount))
  $callCount = 1;
 else
   $callCount++;

 /// do stuff w/ $callCount to potentially handle sub-tabs and stuff
    if($callCount == 2) {
      echo 'white on black';
    } else {
      echo 'black on white';
    }
    echo PHP_EOL;
}

doStuff();
doStuff();
doStuff();
doStuff();
doStuff();
?>

nathan-nobbes-macbook-pro:~ nnobbe$ php testDepth.php
black on white
white on black
black on white
black on white
black on white

o ya and removed the part where the variable is decremented from the
original ;)  (good call there jim) i was thinking the function was going to
be called recursively at first which is why i had it in there and it would
make sense in that case; however since it isnt going to be called
recursively it doesnt.

-nathan

--- End Message ---
--- Begin Message ---
On 9 May 2008, at 02:02, Nathan Nobbe wrote:
function doStuff() {
static $callCount;

if(!isset($callCount))
 $callCount = 1;
else
  $callCount++;

/// do stuff w/ $callCount to potentially handle sub-tabs and stuff
   if($callCount == 2) {
     echo 'white on black';
   } else {
     echo 'black on white';
   }
   echo PHP_EOL;
}

No need for the first if, just give the static var a default value...

function doStuff() {
static $callCount = 0;
$callCount++;
...
}

Much neater.

-Stut

--
http://stut.net/

--- End Message ---
--- Begin Message ---
On Thu, May 8, 2008 at 3:37 PM, Richard Kurth <[EMAIL PROTECTED]>
wrote:

> Dan Joseph wrote:
>
>> On Thu, May 8, 2008 at 11:54 AM, Richard Kurth <
>> [EMAIL PROTECTED]>
>> wrote:
>>
>>
>>
>>> Dan Joseph wrote:
>>>
>>>
>>>
>>>> On Thu, May 8, 2008 at 11:47 AM, Richard Kurth <
>>>> [EMAIL PROTECTED]>
>>>> wrote:
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> I have a program that I am writing that I what to install on my server
>>>>> that
>>>>> can be accessed by all domains on the server just like it was on there
>>>>> domain. Could somebody give me an idea on how I can do this or point me
>>>>> to
>>>>> some article that tells how to set this up.
>>>>>
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>> Accessible as in able to talk to it and pull information, or be able to
>>>> integrate it into the web site?  If its just needing to get data, you
>>>> could
>>>> build a web service and give access to it for all other domains.
>>>>
>>>>
>>>>
>>>>
>>> To Be able to integrate it into the web site is what I am trying to
>>> figure
>>> out
>>>
>>>
>>>
>>>
>> You should be able to configure Apache (assuming you're using Apache) in a
>> way that for instance:  http://domain.com/globalapplication/ would be
>> pointing to a specified folder.  You would just have to tell it to make
>> that
>> path for all domains on the server.  Although that might be better suited
>> for someone on an Apache list or forum to explain better.
>>
>>
>>
> Thanks that is what I needed to know I will now check on an apache list


if your webserver is hosting multiple domains, all you have to do is put the
shared stuff outside the webroots in some common location.  then simply
include that in your scripts in these various places.  the only thing you
have to make sure is the user the webserver is running as has permission to
read from the external location.

say for example you are using linux, you create a directory such as,
/var/www/commonPhpStuff.  and in there you have a class file
FrameworkCore.php or something.  then in all your sites you can simply do
include('/var/www/commonPhpStuff/FrameworkCore.php');

alternatively, you could add '/var/www/commonPhpStuff' to the include_path
in php.ini, a .htaccess file, or a set_ini() call.  then the include call
would become
include('FrameworkCore.php');

-nathan

--- End Message ---
--- Begin Message ---
Sanjeev N wrote:
> Hi Jim Lucas,
> 
> You are correct... i want to run in the same way.
> 
> but as my 2 tables, column name are different i cant run the LOAD DATA
> infile.

If you're inserting the same data, then use LOAD DATA INFILE to load it
into a temporary table, then use INSERT SELECT's to put them into the
other tables.

-- 
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Richard Heyes wrote:
I do not agree that creating a database which is normalised to3NF is a waste of time.

It isn't always, but it is sometimes. When time is a (significant) factor, getting something up and running (which has acceptable performance) may be more impotant than creating a technically perfect solution. In fact creating something that is technically perfect is often just a pipe dream for programmers.

 > On the contrary, a totally un-normalised database is nothing but a
problem waiting to bite you in the a**e.

So you can:

a) Create something that gets you to market as fast as possible that is
   "good enough".
b) Optimise/adjust the structure later.

IME though, b) rarely happens.

 > Computer systems have a habit of
growing over time

Really?

...and if you don't follow the rules of normalisation your database will end up as the biggest bottleneck.

Granted it's more likely, but not a given. You just need developers who have discipline, oh and a good memory helps.

Anyone who doesn't know how to reach 3NF shouldn't be designing databases.

Rubbish. It helps, in particular for how you can optimise you structure without duplicating data (too much), but shouldn't be a requirement.


Me personally I've always found it very productive to take a few hours before I begin coding a project, to roughly flow-chart the basics of the application, and then layout the db on paper to get a graphical view of the tables I'll need, how they relate or don't relate to one another. That way when I do actually create the db I'm usually at 3NF.

--

Mark
-------------------------
the rule of law is good, however the rule of tyrants just plain sucks!
Real Tax Reform begins with getting rid of the IRS.
==============================================
Powered by CentOS5 (RHEL5)

--- End Message ---
--- Begin Message ---
On Wed, May 7, 2008 at 10:05 PM, Thijs Lensselink <[EMAIL PROTECTED]> wrote:

> Quoting Angelo Zanetti <[EMAIL PROTECTED]>:
>
>  Hi Guys,
>>
>> We have a project where by we have a map in ai format (vector format).
>> What
>> we want to do is to programmatically come up with a solution that say on
>> the
>> map there is a restaurant at a certain location, that we can zoom into the
>> map on that specific area.
>>
>> I really am not sure where to start. I guess image maps arent going to
>> work
>> are they?
>>
>> Should I be using the GD library for manipulating the images and doing
>> zooming? Also will the ai format be supported?
>>
>> Please guys, any tips, links or help is appreciated.
>>
>> TIA
>>
>> Angelo
>>
>>
> I think doing something like this with GD is nearly impossible.
>
> But you could import the vector image in flash/flex. Draw an invisible
> grid over it to create some sort of long / lat coordinats.
>
> Or maybe just move to the google / yahoo map API's.
>

I guess GoogleMap API can do this.  But you are working on javascript ..

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

While debugging a script that ran too slowly I came across something that I 
can't explain.

It is inactive code that when removed doubles the run time of the script.

Specifically, the issue is a switch statement, where one of the cases is 
never reached. If I remove the case from the code, the run time of the 
script goes from 6 seconds to 12 seconds.

To see this problem in action, you can download the problematic script here:
http://sebrechts.net/files/2008/phpperfissue.zip

Anyone have any ideas on how this is even possible? I'd like to improve the 
run time of the script, but if every part of code that I take out makes it 
run longer ...

Thanks 



--- End Message ---
--- Begin Message ---
On Wed, 2008-05-07 at 17:31 +0200, Joeri Sebrechts wrote:
> Hello,
> 
> While debugging a script that ran too slowly I came across something that I 
> can't explain.
> 
> It is inactive code that when removed doubles the run time of the script.
> 
> Specifically, the issue is a switch statement, where one of the cases is 
> never reached. If I remove the case from the code, the run time of the 
> script goes from 6 seconds to 12 seconds.
> 
> To see this problem in action, you can download the problematic script here:
> http://sebrechts.net/files/2008/phpperfissue.zip
> 
> Anyone have any ideas on how this is even possible? I'd like to improve the 
> run time of the script, but if every part of code that I take out makes it 
> run longer ...

Runs the same for me either way... under PHP4 and PHP5. You must have a
nice system, takes 22 seconds both ways on my Athlon 2400 :)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


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

I'm struggling with the WDSL restrictions in PHP/SOAP for a while know. I would like to create some simple restrictions in my WDSL file.

The script are running both on the same server with PHP Version 5.2.6 with the 
official soap extension.

On both my client and server there is some error configuration:

error_reporting(E_ALL);

ini_set("soap.wsdl_cache_enabled", "0");
use_soap_error_handler(true);

In my WDSL file there are some restrictions like:

A rule to accept only numbers, PHP/SOAP is translating not numbers to 0. (but I 
want an error message!)

<xsd:element name="streetNumber" minOccurs="1" maxOccurs="1" type="xsd:int">

Almost the same for this more advanced restriction, you can provide every string. There is no error message and the whole string is accepted by my server.

<xsd:simpleType name="Email">
        <xsd:restriction base="xsd:string">
                <xsd:pattern
                        value="^[_a-z0-9-]+(\.[_a-z0-9-]+)[EMAIL 
PROTECTED](\.[a-z0-9-]+)*$">
                </xsd:pattern>
        </xsd:restriction>
</xsd:simpleType>

I hope there are some people that have some more experience with PHP/SOAP and the use of restrictions who can help me with this!

Best regards,

Paul

--- End Message ---
--- Begin Message ---
> I'm struggling with the WDSL restrictions in PHP/SOAP for a while
Sorry, I mean WSDL instead of WDSL.

But of course the problem stays the same :-)

--- End Message ---
--- Begin Message ---
revDAVE wrote:
Newbie - is there a function similar to the sql 'like' comparison operator?

I would like to be able to compare 2 strings:

If $this ---*like or similar to*--- $that

That type of thing...

I strongly suggest you read up on regular expressions:
http://uk.php.net/manual/en/book.regex.php

Knowing how to use regular expressions is a a very handy skill. I do a lot of mass changing of files via the command line with tools such as grep, sed and awk and a mastery regular expressions can save hours of laborious typing and find/replacing ;)

Reminds me of one of my favourite xkcd cartoons:
http://xkcd.com/208/

Col


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

Ho to read date from HTML form ->
How to read $_POST['date']="dd/mm/YYYY" string variable as a date?

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

If I have an array like this:
$arr = array (
                'c' => 'd',
                'e' => 'f');

How can I convert this array into a string? I want to write an array into a
file.

Thanks in advance.

-- 
Regards,
Shelley

--- End Message ---

Reply via email to