php-general Digest 16 Feb 2011 21:16:38 -0000 Issue 7185

Topics (messages 311359 through 311392):

Re: errors after upgrade vom 5.2.10 to 5.3.0 howto solve or hide?
        311359 by: Richard Quadling
        311361 by: Andre Polykanine
        311363 by: Richard Quadling
        311372 by: Daniel P. Brown
        311373 by: David Hutto
        311374 by: Daniel P. Brown
        311375 by: David Hutto
        311376 by: David Hutto
        311377 by: Daniel P. Brown
        311378 by: Richard Quadling
        311380 by: Robert Cummings

Re: Howdy (new in here)
        311360 by: Andre Polykanine
        311379 by: Donovan Brooke

DOMDocument, content of entity
        311362 by: Fanda
        311364 by: Jay Blanchard
        311365 by: Jay Blanchard
        311366 by: Fanda
        311367 by: Fanda
        311368 by: Jay Blanchard
        311369 by: Jay Blanchard
        311370 by: Fanda

Re: Finding split points in an article for inserting ads
        311371 by: Gerardo Benitez

PHP+MySQL question
        311381 by: דניאל דנון
        311382 by: Robert Cummings
        311383 by: Robert Cummings

Re: Custom function
        311384 by: Mark Kelly
        311385 by: Dan Schaefer
        311386 by: Peter Lind
        311387 by: Andre Polykanine
        311388 by: Adam Richardson
        311389 by: Peter Lind
        311390 by: Peter Lind
        311391 by: Paul M Foster
        311392 by: Peter Lind

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 ---
On 16 February 2011 09:12,  <[email protected]> wrote:
> Hi everyone!

Hi.

Please read the changelog http://docs.php.net/ChangeLog-5.php#5.3.0
and do a search for ereg. You'll notice that it has been deprecated.

As such, old code that relies on this feature may no longer work as
expected and/or give a warning - just like you are seeing.

Your main choices at this stage are :

1 - Upgrade Typo3 to a compatible version for the version of PHP you
are using. Looking at the latest version
(https://svn.typo3.org/TYPO3v4/Core/tags/TYPO3_4-5-0/t3lib/class.t3lib_page.php)
no longer uses ereg_*(), but preg_*().
2 - Downgrade your PHP version back to the lowest version that is
compatible with your installation of Typo3.
3 - Do a LOT of hacking and hope for the best.

Personally, I'd revert the upgrade of PHP and then create a separate
vhost or site to install/configure/test/upgrade the data from the old
version to the new one.

Also, any plugins/extensions/mods that may have been applied may also
need to be upgraded accordingly.

Regards,

Richard.

P.S. The PHP mailing lists is probably not the best place to come for
support on Typo3. I've never used Typo3 or installed it. But, in this
instance, GWMF.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

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

           <?
error_reporting(0);


-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: [email protected] <[email protected]>
To: [email protected]
Date created: , 11:12:13 AM
Subject: [PHP] errors after upgrade vom 5.2.10 to 5.3.0  howto solve or hide?


      Hi everyone!


after upgrading vomn php 5.2.10 to 5.3.0 I get a lot of errors. I changed 
already in some files ereg_replace() to  preg_replace(), but it generates more 
errors as you can see.

The typo3 installation ins still working. 

So - how can I prevent php from printing out this errors on the beginning at 
the website?

display_errors = Off   in  php.ini


Any Ideas?
Greetz.





Warning: preg_replace() [function.preg-replace]: Delimiter must not be 
alphanumeric or backslash in /typo3_src-3.8.1/t3lib/class.t3lib_page.php on 
line 436

Warning: preg_replace() [function.preg-replace]: Delimiter must not be 
alphanumeric or backslash in /typo3_src-3.8.1/t3lib/class.t3lib_page.php on 
line 438

Warning: preg_replace() [function.preg-replace]: Delimiter must not be 
alphanumeric or backslash in /typo3_src-3.8.1/t3lib/class.t3lib_page.php on 
line 441

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_matchcondition.php on line 527

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_matchcondition.php on line 527

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 801

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 809

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 801

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 809

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 801

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 809

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/typo3/sysext/cms/tslib/class.tslib_content.php on line 2748

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/typo3/sysext/cms/tslib/class.tslib_content.php on line 2752

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 801

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 809

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_stdgraphic.php on line 2097

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_stdgraphic.php on line 2164

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 801

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 809

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_stdgraphic.php on line 2097

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_stdgraphic.php on line 2164

Deprecated: Function spliti() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_parsehtml.php on line 227

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1583

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1585

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1583

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1585

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1583

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1585

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1583

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1585

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function spliti() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_parsehtml.php on line 227

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1583

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1585

Deprecated: Function split() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1598

Deprecated: Function ereg_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1558

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1583

Deprecated: Function eregi_replace() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 1585

Deprecated: Function call_user_method() is deprecated in 
/typo3_src-3.8.1/typo3/sysext/cms/tslib/class.tslib_content.php on line 5415

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 801

Deprecated: Function ereg() is deprecated in 
/typo3_src-3.8.1/t3lib/class.t3lib_div.php on line 809

Warning: Cannot modify header information - headers already sent by (output 
started at /typo3_src-3.8.1/t3lib/class.t3lib_page.php:436) in 
/typo3_src-3.8.1/typo3/sysext/cms/tslib/class.tslib_fe.php on line 2614
-- 
NEU: FreePhone - kostenlos mobil telefonieren und surfen!                       
Jetzt informieren: http://www.gmx.net/de/go/freephone

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


--- End Message ---
--- Begin Message ---
On 16 February 2011 11:25, Andre Polykanine <[email protected]> wrote:
> Hello Fotoo,
>
>           <?
> error_reporting(0);

Really?

You consider shoving your head in the sand a REALISTIC option?


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 07:15, Richard Quadling <[email protected]> wrote:
> On 16 February 2011 11:25, Andre Polykanine <[email protected]> wrote:
>> Hello Fotoo,
>>
>>           <?
>> error_reporting(0);
>
> Really?
>
> You consider shoving your head in the sand a REALISTIC option?

    Well, at the least, it would shut the errors up in the meantime,
pending an actual resolution.  However, the use of short_open_tags may
completely defeat the intended purpose.

-- 
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 9:34 AM, Daniel P. Brown
<[email protected]> wrote:
> On Wed, Feb 16, 2011 at 07:15, Richard Quadling <[email protected]> wrote:
>> On 16 February 2011 11:25, Andre Polykanine <[email protected]> wrote:
>>> Hello Fotoo,
>>>
>>>           <?
>>> error_reporting(0);
>>
>> Really?
>>
>> You consider shoving your head in the sand a REALISTIC option?
>
>    Well, at the least, it would shut the errors up in the meantime,
> pending an actual resolution.  However, the use of short_open_tags may
> completely defeat the intended purpose.
>
> --
> </Daniel P. Brown>
> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
> (866-) 725-4321
> http://www.parasane.net/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

What was the intended purpose again?

-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.

--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 09:37, David Hutto <[email protected]> wrote:
>
> What was the intended purpose again?

    The hiding of errors.

-- 
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--- End Message ---
--- Begin Message ---
Only those who live in glass houses, should hide their errors.

--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 9:41 AM, David Hutto <[email protected]> wrote:
> Only those who live in glass houses, should hide their errors.
>


if that makes sense.
-- 
According to theoretical physics, the division of spatial intervals as
the universe evolves gives rise to the fact that in another timeline,
your interdimensional counterpart received helpful advice from me...so
be eternally pleased for them.

--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 09:41, David Hutto <[email protected]> wrote:
> On Wed, Feb 16, 2011 at 9:41 AM, David Hutto <[email protected]> wrote:
>> Only those who live in glass houses, should hide their errors.
>>
>
>
> if that makes sense.

    Did you even bother to read the whole of what I said?  I wasn't
advocating it as a solution, I simply said it was a temporary fix
pending a real resolution.

-- 
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--- End Message ---
--- Begin Message ---
On 16 February 2011 14:34, Daniel P. Brown <[email protected]> wrote:
> On Wed, Feb 16, 2011 at 07:15, Richard Quadling <[email protected]> wrote:
>> On 16 February 2011 11:25, Andre Polykanine <[email protected]> wrote:
>>> Hello Fotoo,
>>>
>>>           <?
>>> error_reporting(0);
>>
>> Really?
>>
>> You consider shoving your head in the sand a REALISTIC option?
>
>    Well, at the least, it would shut the errors up in the meantime,
> pending an actual resolution.  However, the use of short_open_tags may
> completely defeat the intended purpose.
>
> --
> </Daniel P. Brown>
> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
> (866-) 725-4321
> http://www.parasane.net/
>

Because some of the code has been edited, it is now broken. Hiding the
errors at that stage is really driving with your eyes closed.

If the changes are reverted, so that ereg is still used rather than
preg, and the deprecation notices suppressed, then that maybe the best
place to be for the short term.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

--- End Message ---
--- Begin Message ---
On 11-02-16 09:45 AM, Daniel P. Brown wrote:
On Wed, Feb 16, 2011 at 09:41, David Hutto<[email protected]>  wrote:
On Wed, Feb 16, 2011 at 9:41 AM, David Hutto<[email protected]>  wrote:
Only those who live in glass houses, should hide their errors.



if that makes sense.

     Did you even bother to read the whole of what I said?  I wasn't
advocating it as a solution, I simply said it was a temporary fix
pending a real resolution.

Just plop a .htaccess file (or modify one if it already exists) into the typo3 root web folder. In it disable E_DEPRECATED warnings. Also, the OP appears to have introduced errors by renaming ereg to preg. Did he check the syntax for preg versus ereg? His delimiters are conflicting with the pattern or are non-existent.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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

And I prefer this:

if ($foo==$baz)
:-).  I  don't know if it's kosher not to put spaces around the == but
still...
-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: Micky Hulse <[email protected]>
To: [email protected]
Date created: , 3:43:57 AM
Subject: [PHP] Howdy (new in here)


      On Tue, Feb 15, 2011 at 2:00 PM, David Harkness
<[email protected]> wrote:
> I use K&R. I started with it just as shown but as monitors increased in size
> I stopped cuddling the else so it's now on its own line, aligning the if,
> elseif, and else nicely. One of the developers at my company uses the
> truly abominable Horstmann style which makes moving code around a serious

K&R here, unless existing guidelines are in place... CodeIgniter
framework and ExpressionEngine wants folks to use Allman.

I use a programming lang called Objectscript at work, and it will give
an error if there is not space between the "if" and the first "("...
For example:

if(...) <-- errors out.

I have had to learn to put a space in there:

if (...)

So I don't forget, I do this for everything now... I actually kinda
like the breathing room now.

Speaking of spaces, I am not a fan of putting spaces around the argument:

if ( foo == baz ) {

I definitely prefer this:

if (foo == baz) {

More on spaces: I am so glad that most PHP folks I know use tabs for
indentation and not spaces! Oops, did I just go there? Oh no I didn't!

Good thread! Thanks for that link Tedd!

Cheers,
Micky

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


--- End Message ---
--- Begin Message ---
Tamara Temple wrote:

On Feb 15, 2011, at 4:17 PM, Donovan Brooke wrote:

[snip]
This is what I show my students:

http://rebel.lcc.edu/sperlt/citw229/brace-styles.php

Cheers,

tedd


I didn't know there were names for bracing styles... but

Neither did I -- just the K&R style was the only name I recognized. (I
still have a first edition!)

However, I think on my next project, I will use "Whitesmith's Style".

I would be more inclined to try other styles if my editor of choice,
TextMate, were to easily support them; as it is now, TextMate
automatically un-indents the line when you type a closing } on an open
line, and automatically indents on an open line after a opening { -- so,
what to do? I don't really want to dive into programming my editor's
functions (which I could do with TextMate) as that is really getting
into non-productive tweaking.

The issue I had at times with the K&R style was locating the the
matching (open or closed) brace.. as they were not on the same
character column.

I never really found this to be a problem as long as I kept the various
branches short enough. I was unlucky enough to find someone who coded a
function that went on for 30 pages one (this was in C, not PHP) and
*that* was hard to untangle. Of course, one of the first things I did
when I had a spare moment was to chop it up in to individual functions....


Well, in either case it add's a bit of complexity.. if you are not searching for an end brace, you are scrolling to find a function (or include file perhaps)... but yes, I try to keep them short as well.

One thing I do at times is comment what end brace is what..

} // end to: if $num == 6

I still can't get away from BBedit, but the only automatic thing I have
turned on is text suggestion... which I think about turning off every time I code. ;-)



--
D Brooke

--- End Message ---
--- Begin Message ---
Hi, does anybody know, how can I parse (by DOMDocument::loadHTMLFile) content 
of <td> tag, containing string in 3 rows (<br>)? I need it to split to 3 
strings.
Thanks. Fanda

--- End Message ---
--- Begin Message ---
[snip]
Hi, does anybody know, how can I parse (by DOMDocument::loadHTMLFile)
content of <td> tag, containing string in 3 rows (<br>)? I need it to
split to 3 strings.
[/snip]

http://www.php.net/explode

--- End Message ---
--- Begin Message ---
[snip]
Hi, does anybody know, how can I parse (by DOMDocument::loadHTMLFile)
content of <td> tag, containing string in 3 rows (<br>)? I need it to
split to 3 strings.
[/snip]

http://www.php.net/explode

--- End Message ---
--- Begin Message ---
> http://www.php.net/explode

I know it, but when I get content of <td> by $cols->item(0)->nodeValue, it is 
without <br> tags. So I need to:
a) get content with tags also or
b) split content by DOM (if it is possible) and get 3 different parts

--- End Message ---
--- Begin Message ---
> http://www.php.net/explode

I know it, but when I get content of <td> by $cols->item(0)->nodeValue, it is 
without <br> tags. So I need to:
a) get content with tags also or
b) split content by DOM (if it is possible) and get 3 different parts

--- End Message ---
--- Begin Message ---
[snip]
> http://www.php.net/explode

I know it, but when I get content of <td> by $cols->item(0)->nodeValue,
it is without <br> tags. So I need to:
a) get content with tags also or
b) split content by DOM (if it is possible) and get 3 different parts
[/snip]

The DOM only exists in the browser, it really isn't available
server-side (it is proposed). What does this data look like? Is it just
strings?

--- End Message ---
--- Begin Message ---
[snip]
The DOM only exists in the browser, it really isn't available
server-side (it is proposed). What does this data look like? Is it just
strings?
[/snip]

Have you tried DOMDocument::loadHTML?

--- End Message ---
--- Begin Message ---
No I have not. Should I? Works it different way from 
DOMDocument::loadHTMLFile()? Data looks like this:

<tr>
    <td><b>Name</b> Address<b><i> Contact</i></b></td>
    <td class="b">ID: 3517438<br/>Category<br/>Date</td>
</tr>


""Jay Blanchard"" <[email protected]> píse v diskusním príspevku 
news:[email protected]...
[snip]
The DOM only exists in the browser, it really isn't available
server-side (it is proposed). What does this data look like? Is it just
strings?
[/snip]

Have you tried DOMDocument::loadHTML?

--- End Message ---
--- Begin Message ---
I think you can do it any of both, is only a matter of taste.

Gerardo.


On Wed, Feb 16, 2011 at 1:26 AM, Tamara Temple <[email protected]>wrote:

>
>
> Dear list,
>
> I want to extend the original question to a discussion about the relative
> merits of doing this within PHP vs. doing it afterwards in JavaScript. I can
> see arguments for both sides, so I would like get opinions from others on
> this tradeoff.
>
>

-- 
Gerardo Benitez
-------------------------
www.webseficientes.com.ar
Diseño web, programación, Seo

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

I have a table called "images" with 4 columns - `image_id`, `item_name`,
`image_url`,  `image_views`
(Where image_id is UNIQUE and AUTO-INCREMENT).

Sometimes, there might be many items with the same name (but not with the
same url).

I want to make sure that each "item name" has at most 3 images (and
therefore I need to delete the rest).
The problem is that I want to keep the images with the most views.


I've tried to look for efficient solutions either in MySQL or in PHP, but
they are mostly very resource-intensive,
Such as selecting all different names in PHP (using GROUP BY), then, for
each name, doing DELETE FROM images WHERE item_name = 'ITEM-NAME-HERE' ORDER
BY image_views ASC LIMIT (here some sub-query with count on how many rows
have the name ITEM-NAME-HERE minus 3).


I'd be glad if anyone could help me or point me to the right direction.


Daniel.

-- 
Use ROT26 for best security

--- End Message ---
--- Begin Message ---
On 11-02-16 11:37 AM, דניאל דנון wrote:
Hi.

I have a table called "images" with 4 columns - `image_id`, `item_name`,
`image_url`,  `image_views`
(Where image_id is UNIQUE and AUTO-INCREMENT).

Sometimes, there might be many items with the same name (but not with the
same url).

I want to make sure that each "item name" has at most 3 images (and
therefore I need to delete the rest).
The problem is that I want to keep the images with the most views.


I've tried to look for efficient solutions either in MySQL or in PHP, but
they are mostly very resource-intensive,
Such as selecting all different names in PHP (using GROUP BY), then, for
each name, doing DELETE FROM images WHERE item_name = 'ITEM-NAME-HERE' ORDER
BY image_views ASC LIMIT (here some sub-query with count on how many rows
have the name ITEM-NAME-HERE minus 3).


I'd be glad if anyone could help me or point me to the right direction.

I'd use a cron job to manage the purging process... and off the top of my head I'd probably go the following route:

Get the list of images with more than 3 of the same name:

SELECT item_name, SUM( 1 ) AS total FROM images HAVING total > 3;

Get the 3 best images for each image returned above:

SELECT image_id FROM images WHERE image_name = '[[NAME]]' ORDER BY image_views DESC.

(Make sure to quote your criteria properly in the above-- this is pseudo codish).

Now delete the laggards using the ID we just retrieved:

DELETE FROM images WHERE image_id NOT IN ([[ID_LIST]]).

That should get you to a decent solution.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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


On 11-02-16 11:55 AM, Robert Cummings wrote:
On 11-02-16 11:37 AM, דניאל דנון wrote:
Hi.

I have a table called "images" with 4 columns - `image_id`, `item_name`,
`image_url`,  `image_views`
(Where image_id is UNIQUE and AUTO-INCREMENT).

Sometimes, there might be many items with the same name (but not with the
same url).

I want to make sure that each "item name" has at most 3 images (and
therefore I need to delete the rest).
The problem is that I want to keep the images with the most views.


I've tried to look for efficient solutions either in MySQL or in PHP, but
they are mostly very resource-intensive,
Such as selecting all different names in PHP (using GROUP BY), then, for
each name, doing DELETE FROM images WHERE item_name = 'ITEM-NAME-HERE' ORDER
BY image_views ASC LIMIT (here some sub-query with count on how many rows
have the name ITEM-NAME-HERE minus 3).


I'd be glad if anyone could help me or point me to the right direction.

I'd use a cron job to manage the purging process... and off the top of
my head I'd probably go the following route:

Get the list of images with more than 3 of the same name:

SELECT item_name, SUM( 1 ) AS total FROM images HAVING total>  3;

Get the 3 best images for each image returned above:

SELECT image_id FROM images WHERE image_name = '[[NAME]]' ORDER BY
image_views DESC.

Oops... that should have a LIMIT clause on it:

SELECT image_id FROM images WHERE image_name = '[[NAME]]' ORDER BY image_views DESC LIMIT 3

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

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

On Wednesday 16 Feb 2011 at 00:49 Simon J Welsh wrote:

> As $z is converted to a boolean and exists, that works just the same way as
>  !empty(). ---

First I'd like to apologise for handing out bad advice, and second, to thank 
Simon and Andre for pointing out my mistake. I'll go back to keeping my mouth 
shut in future :)

Cheers guys,

Mark

--- End Message ---
--- Begin Message --- In my code, I set the optional parameter to NULL and check for triple equals "===" or "!==" to see if the variable has been passed with a value. IMO, this is the safest way.

function MyFunction($x, $y, $z=NULL) {
if ($z !== NULL) {
// Do Something
}
}

Dan Schaefer
Web Developer/Systems Analyst
Performance Administration Corp.


On 2-15-2011 6:32 PM, Ron Piggott wrote:
Is there a way to make an optional flag in a custom function --- 2 parameters 
required, 1 optional?  Ron

The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info


--- End Message ---
--- Begin Message ---
On 16 February 2011 21:00, Dan Schaefer <[email protected]> wrote:
> In my code, I set the optional parameter to NULL and check for triple equals
> "===" or "!==" to see if the variable has been passed with a value. IMO,
> this is the safest way.
>
> function MyFunction($x, $y, $z=NULL) {
> if ($z !== NULL) {
> // Do Something
> }
> }

In case you're actually trying to test if a variable was passed or not
that doesn't work (as it doesn't detect NULL passed in). Use
func_get_args() as that gives you any and all arguments passed to the
function, excluding defaults.

That said, if you're making use of optional parameters and need to
check if anything was passed in, you're almost certainly doing things
wrong.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

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

So is
func_get_args()
     the unique way?

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: Peter Lind <[email protected]>
To: Dan Schaefer
Date created: , 10:21:20 PM
Subject: [PHP] Custom function


      On 16 February 2011 21:00, Dan Schaefer <[email protected]> wrote:
> In my code, I set the optional parameter to NULL and check for triple equals
> "===" or "!==" to see if the variable has been passed with a value. IMO,
> this is the safest way.
>
> function MyFunction($x, $y, $z=NULL) {
> if ($z !== NULL) {
> // Do Something
> }
> }

In case you're actually trying to test if a variable was passed or not
that doesn't work (as it doesn't detect NULL passed in). Use
func_get_args() as that gives you any and all arguments passed to the
function, excluding defaults.

That said, if you're making use of optional parameters and need to
check if anything was passed in, you're almost certainly doing things
wrong.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

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


--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 3:21 PM, Peter Lind <[email protected]> wrote:

> On 16 February 2011 21:00, Dan Schaefer <[email protected]> wrote:
> > In my code, I set the optional parameter to NULL and check for triple
> equals
> > "===" or "!==" to see if the variable has been passed with a value. IMO,
> > this is the safest way.
> >
> > function MyFunction($x, $y, $z=NULL) {
> > if ($z !== NULL) {
> > // Do Something
> > }
> > }
>
> In case you're actually trying to test if a variable was passed or not
> that doesn't work (as it doesn't detect NULL passed in). Use
> func_get_args() as that gives you any and all arguments passed to the
> function, excluding defaults.
>

I'm not sure what you're saying here, Peter? Are you saying that the code
wouldn't detect if $z was set to NULL by the calling code or by the default?
I believe the point would be that no matter the case, the check would still
perform the same task.

Maybe I misunderstood (sorry.)


>
> That said, if you're making use of optional parameters and need to
> check if anything was passed in, you're almost certainly doing things
> wrong.
>

I sometimes use this approach. PHP doesn't to my knowledge allow you to use
function calls within defaults. There are times that I want the default to
be the result of a function, and to accomplish this, I'll often set the
default to null, then check for the null and carry out the function within.

Is there a better solution?

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com

--- End Message ---
--- Begin Message ---
On 16 February 2011 21:45, Andre Polykanine <[email protected]> wrote:
> Hello Peter,
>
> So is
> func_get_args()
>     the unique way?
>

Not really sure what you mean by the unique way. Most things proposed
so far in the thread would be fine for most purposes, I'd say. If you
really need finegrained control, I'd suggest func_get_args.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

--- End Message ---
--- Begin Message ---
On 16 February 2011 21:45, Adam Richardson <[email protected]> wrote:
> On Wed, Feb 16, 2011 at 3:21 PM, Peter Lind <[email protected]> wrote:
>
>> On 16 February 2011 21:00, Dan Schaefer <[email protected]> wrote:
>> > In my code, I set the optional parameter to NULL and check for triple
>> equals
>> > "===" or "!==" to see if the variable has been passed with a value. IMO,
>> > this is the safest way.
>> >
>> > function MyFunction($x, $y, $z=NULL) {
>> > if ($z !== NULL) {
>> > // Do Something
>> > }
>> > }
>>
>> In case you're actually trying to test if a variable was passed or not
>> that doesn't work (as it doesn't detect NULL passed in). Use
>> func_get_args() as that gives you any and all arguments passed to the
>> function, excluding defaults.
>>
>
> I'm not sure what you're saying here, Peter? Are you saying that the code
> wouldn't detect if $z was set to NULL by the calling code or by the default?
> I believe the point would be that no matter the case, the check would still
> perform the same task.
>
> Maybe I misunderstood (sorry.)

The point is the poster seemed to suggest the safest way to use
optional parameters was to use null as the default value and use ===
null to check against the optional parameter - as a way to check if
anything was passed in or not. I just pointed out that that would fail
to check for a null passed in and that func_get_args() would be a
better match. You're obviously right that the check inside the
function would work the same whether null was passed in or the value
was defaulted to null.

>
>>
>> That said, if you're making use of optional parameters and need to
>> check if anything was passed in, you're almost certainly doing things
>> wrong.
>>
>
> I sometimes use this approach. PHP doesn't to my knowledge allow you to use
> function calls within defaults. There are times that I want the default to
> be the result of a function, and to accomplish this, I'll often set the
> default to null, then check for the null and carry out the function within.
>
> Is there a better solution?

As noted in the post, func_get_args will show any and all (at least on
my 5.3.3 install and 5.2.6 install) values passed in to the function -
hence it will also show if no parameter was passed in (and is thus
safer than relying on the default value).
That noted, I don't think checking if a value was passed in is good
design - I think the function should be ignorant of what is passed to
it. But that's just me :)

Regards
Peter


-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

--- End Message ---
--- Begin Message ---
On Wed, Feb 16, 2011 at 09:21:20PM +0100, Peter Lind wrote:

> On 16 February 2011 21:00, Dan Schaefer <[email protected]> wrote:
> > In my code, I set the optional parameter to NULL and check for triple
> equals
> > "===" or "!==" to see if the variable has been passed with a value. IMO,
> > this is the safest way.
> >
> > function MyFunction($x, $y, $z=NULL) {
> > if ($z !== NULL) {
> > // Do Something
> > }
> > }
> 
> In case you're actually trying to test if a variable was passed or not
> that doesn't work (as it doesn't detect NULL passed in). Use
> func_get_args() as that gives you any and all arguments passed to the
> function, excluding defaults.

This must be my week to make enemies.

I beg to differ. If the user passes in NULL for $z or passes in nothing
for that variable, it does in fact show up as NULL. The following test
code works as indicated:

function pizza($a, $b, $c = NULL)
{
        if ($c === NULL)
                echo "c is null<br>\n";
        elseif ($c !== NULL)
                echo "c is not null. it has a value of $c<br>\n";
        else
                echo "indeterminate: c is $c<br>\n";
}   
 
pizza(1, 2, NULL);
pizza(1, 2, 3);
pizza(1, 2);

=-=-=-=-=-=-=

The responses in the first and third cases are NULL. You might be able
to argue that in the first case, where the user passed in NULL, it's
not the same as if the user passed in nothing. But I would assume that the
author considers NULL a signal value, such that if the user passed such
a value in, it would be equivalent to not passing a value for the third
parameter.

> 
> That said, if you're making use of optional parameters and need to
> check if anything was passed in, you're almost certainly doing things
> wrong.

Again, assuming you're talking about examples like the one above, I have
to disagree. Presumably, passing in an optional parameter changes the
action inside the function. Thus, you would *need* to test for its
presence. Otherwise, you would be stuck with assuming it's there,
attempting to use it on that assumption, and dealing with whatever
errors it causes when-- surprise!-- it's not there.

Paul

-- 
Paul M. Foster
http://noferblatz.com


--- End Message ---
--- Begin Message ---
On 16 February 2011 22:04, Paul M Foster <[email protected]> wrote:
> On Wed, Feb 16, 2011 at 09:21:20PM +0100, Peter Lind wrote:
>
>> On 16 February 2011 21:00, Dan Schaefer <[email protected]> wrote:
>> > In my code, I set the optional parameter to NULL and check for triple
>> equals
>> > "===" or "!==" to see if the variable has been passed with a value. IMO,
>> > this is the safest way.
>> >
>> > function MyFunction($x, $y, $z=NULL) {
>> > if ($z !== NULL) {
>> > // Do Something
>> > }
>> > }
>>
>> In case you're actually trying to test if a variable was passed or not
>> that doesn't work (as it doesn't detect NULL passed in). Use
>> func_get_args() as that gives you any and all arguments passed to the
>> function, excluding defaults.
>
> This must be my week to make enemies.
>
> I beg to differ. If the user passes in NULL for $z or passes in nothing
> for that variable, it does in fact show up as NULL. The following test
> code works as indicated:

Did anyone say it wouldn't?

>
> The responses in the first and third cases are NULL. You might be able
> to argue that in the first case, where the user passed in NULL, it's
> not the same as if the user passed in nothing. But I would assume that the
> author considers NULL a signal value, such that if the user passed such
> a value in, it would be equivalent to not passing a value for the third
> parameter.

The point I was trying to make was specifically that someone might try
to distinguish whether a value was passed in for an optional parameter
or not (like the case Adam outlined). Relying on the value of the
optional parameter will not do, in that case (well it might, depending
upon how stringent you really need to be).

>>
>> That said, if you're making use of optional parameters and need to
>> check if anything was passed in, you're almost certainly doing things
>> wrong.
>
> Again, assuming you're talking about examples like the one above, I have
> to disagree. Presumably, passing in an optional parameter changes the
> action inside the function. Thus, you would *need* to test for its
> presence. Otherwise, you would be stuck with assuming it's there,
> attempting to use it on that assumption, and dealing with whatever
> errors it causes when-- surprise!-- it's not there.

You should be wary of assumptions, they're not really working out for you.
- a) you're not addressing Adam's use case
- b) I wouldn't need to test for any presence if I wrote the function
as I would personally prefer, i.e. not trying to test if any value was
passed to the function or not. That's the whole point of optional
values: even if nothing is passed in, there's a default value. That's
why trying to check if something was passed for the optional parameter
is counter-productive: the idea of the default value is that you
shouldn't have to check.

Regards
Peter

-- 
<hype>
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
</hype>

--- End Message ---

Reply via email to