php-general Digest 13 Jul 2008 12:31:32 -0000 Issue 5566
Topics (messages 276709 through 276721):
Re: IPv6 validation
276709 by: Robert Cummings
276717 by: Per Jessen
276718 by: Kevin Waterson
Re: Most popular per month
276710 by: Wolf
276712 by: Brady Mitchell
PDO Question. Number of rows returned
276711 by: Stephen
276716 by: Kevin Waterson
Saving loading time at counting rows
276713 by: Joep Roebroek
276714 by: tedd
276715 by: Robert Cummings
276719 by: Colin Guthrie
276720 by: Per Jessen
Re: case and accent - insensitive regular expression?
276721 by: Andrew Ballard
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 Sun, 2008-07-13 at 07:02 +1000, Kevin Waterson wrote:
> This one time, at band camp, Yeti <[EMAIL PROTECTED]> wrote:
>
> > It will still take some time until every provider has PHP5 running, at least
> > where I am from. I have many customers who want me to get their sites
> > running on some cheap webspace they got along with their internet
> > connection. Then you have to tell them it won't work because of some problem
> > with the versions. I would love to write code for PHP5+ only.This is a
> > terrible excuse for using
>
> PHP 4. Today, July 13, marks 4 years since
> the release of PHP 5.0. _4 YEARS_ to move applications and code to PHP5.
>
> Its either apathy or incometence.
I think apathy... for those who don't give a damn about OOP or the
advanced OOP features, PHP5 brought little to the table while often
requiring work to get your code there. Then followed multiple versions
each with their own quirks all the while tightening a noose of OOP
correctness around the developer who didn't care about some purists OOP
philosophies. Finally, and this isn't particularly true anymore, PHP5
was much slower in earlier versions.
And yes, I've modified my own code as things have progressed, but I
certainly do have clients that didn't want me wasting their money
converting their code-base (not originally written by me) to PHP5. And
yes, I've seen terrible things in the code that PHP5 certainly did
break. And again, yes, some of this was due to poor coding on the
original developer's part... but hey, it DID work in PHP4.
By forcing an end of life, PHP did a favour to all those developers who
couldn't really make the case to their bosses or clients by forcing it
upon them. The issue became much more salient at that point.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Kevin Waterson wrote:
> This one time, at band camp, Yeti <[EMAIL PROTECTED]> wrote:
>
>> It will still take some time until every provider has PHP5 running,
>> at least where I am from. I have many customers who want me to get
>> their sites running on some cheap webspace they got along with their
>> internet connection. Then you have to tell them it won't work because
>> of some problem with the versions. I would love to write code for
>> PHP5+ only.This is a terrible excuse for using
>
> PHP 4. Today, July 13, marks 4 years since
> the release of PHP 5.0. _4 YEARS_ to move applications and code to
> PHP5.
> Its either apathy or incometence.
No, it's a simple matter of need. People also run apache 1.x, mysql 3.x
etc. There are still Linux 2.2 and 2.4 systems out there too.
Besides, the migration path of php4-5 is not always easy - code may
have to be rewritten, other code may not work at all etc. I have two
applications that can only run on php 4.3.8 due to a regression of the
setlocale() function in later versions.
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
This one time, at band camp, Per Jessen <[EMAIL PROTECTED]> wrote:
> No, it's a simple matter of need. People also run apache 1.x, mysql 3.x
> etc. There are still Linux 2.2 and 2.4 systems out there too.
4 years its been, thats incompetence.
Kevin
--- End Message ---
--- Begin Message ---
<snip>
..
.
$perc50=(img50 int)/$total;
You can do it per day, per month, per year, per 28 days, per PMS cycle,
per anything you want provided you have the data to do it.
</snip>
:) this is the part where i am a bit confused actually, can you give me one or
two examples and i'll work from there?
What you have to do is get all the pictures viewed for a specific
day/time frame (you said this was all tracked in a DB anyways) and then
add up all the totals and perform the same calculations using the views
all added over the days all added.
$img1=img1 int day1 +img1 int day2 +img1 int day3 .... img1 int day30
$total= img1 int day1 +img2 int day 1+img3 int day1 +...img50 int day30
$img1perc= $img1/$total
--- End Message ---
--- Begin Message ---
On Jul 11, 2008, at 555PM, Ryan S wrote:
before the next days counter starts this data is stored in a table
which has a simple structure like this
img_id1 int,img_id2 int (etc till img_id10)
That sounds like a painful db structure to deal with if you want to
add more images in the future. I'd suggest a structure more like:
img_id
date_viewed
counter
Where counter is simply the number of times the specified image was
viewed on that day. I just finished writing a blog post about a
similar requirement that may help - http://bradym.net/mysql/logging-requests-with-mysql
.
Now the client wants a little extra functionality, and with me
sucking at maths I need some help please, basically he now wants to
have a chart with all the 50 images there and showing _via
percentages_ instead of the present 1-10 display which ones are the
most popular till date.
You get the percentage simply by dividing the number of requests for a
specific image by the total number of requests for all images. So if
you had the following data:
img1 - 50 views
img2 - 20 views
img3 - 15 views
img4 - 10 views
img5 - 5 views
To get the total, you would just add all those views together (100) in
this case. Then for the percentages just divide each one by 100, ie:
$img1_percent = 50 / 100;
Also, if i am not mistaken there was some charting software to
display this kind of data in pie and line charts... anybody know
what i am talking about? because i cant find such a link in my
bookmarks.
There are several options for charting, here's a post I came across
earlier in the week with some options: http://free-wiz.blogspot.com/2008/07/best-free-chart-apis.html
.
Brady
--- End Message ---
--- Begin Message ---
I am switching to PDO and can't find an equivalent to mysql_num_rows.
Am I missing something silly?
Or is there a change of thinking needed for PDO?
How should I determine how many rows a query returned?
Thanks
Stephen
--- End Message ---
--- Begin Message ---
This one time, at band camp, Stephen <[EMAIL PROTECTED]> wrote:
> I am switching to PDO and can't find an equivalent to mysql_num_rows.
>
> Am I missing something silly?
>
> Or is there a change of thinking needed for PDO?
>
> How should I determine how many rows a query returned?
PDO returns an array, sizeof/count will get you home
Kevin
http://phpro.org
--- End Message ---
--- Begin Message ---
I had this question, which I didn't really know where to ask, so I
thought to begin at this mailing list.
Very basicly said, I count the rows of a table which had approx 50000
or more rows.
The problem is, there is a notable difference in loading time with
other pages. Is there a technique to estimate the number of rows
instead of exactly couting them? So that it saves loading time.
For example, when you search with google, you get an estimate of the
number of results, how do they do this?
Maybe this is not a question for the PHP Mailing list, but if not
where is a better place to ask this?
regards,
Joep
--- End Message ---
--- Begin Message ---
At 2:26 AM +0200 7/13/08, Joep Roebroek wrote:
I had this question, which I didn't really know where to ask, so I
thought to begin at this mailing list.
Very basicly said, I count the rows of a table which had approx 50000
or more rows.
The problem is, there is a notable difference in loading time with
other pages. Is there a technique to estimate the number of rows
instead of exactly couting them? So that it saves loading time.
For example, when you search with google, you get an estimate of the
number of results, how do they do this?
Maybe this is not a question for the PHP Mailing list, but if not
where is a better place to ask this?
regards,
Joep
Joep:
If it was me and the number of rows were not critical, then I would
do it once a day and store that "count" in a table where I needed an
approximate number. Then loading that number for the rest of the day
would be instant.
You don't need a cron job for that, just tie a date to the "count"
entry and have each access to it compare the date with current date.
If the date is 24 hours since the last update, then that lucky person
has to wait a bit longer than most while a count is establish and
recorded.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Sat, 2008-07-12 at 23:22 -0400, tedd wrote:
> At 2:26 AM +0200 7/13/08, Joep Roebroek wrote:
> >I had this question, which I didn't really know where to ask, so I
> >thought to begin at this mailing list.
> >
> >Very basicly said, I count the rows of a table which had approx 50000
> >or more rows.
You are counting all the rows, or only rows mathcing a specific set of
criteria? Have you checked that you are indexing appropriate columns?
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
Joep Roebroek wrote:
I had this question, which I didn't really know where to ask, so I
thought to begin at this mailing list.
Very basicly said, I count the rows of a table which had approx 50000
or more rows.
The problem is, there is a notable difference in loading time with
other pages. Is there a technique to estimate the number of rows
instead of exactly couting them? So that it saves loading time.
For example, when you search with google, you get an estimate of the
number of results, how do they do this?
Maybe this is not a question for the PHP Mailing list, but if not
where is a better place to ask this?
Sadly you didn't say which database you are using... so I'll give you an
answer for MySQL... I don't know what other DBs do.
Say you have:
SELECT * FROM table WHERE condition;
You only show the n results but these may be "paged" or offset.
What I would do here is:
SELECT SQL_CALC_FOUND_ROWS * FROM table WHERE condition LIMIT n OFFSET y;
This limits how many results MySQL actually gives you *but* allows you
to know what the full number of results would have been if you hadn't
used LIMIT via a second statement:
SELECT FOUND_ROWS()
Hopefully that solves your issue, but perhaps I've missed what you are
actually trying to do.
Col
Is that the kind of answer you are looking for?
--- End Message ---
--- Begin Message ---
Joep Roebroek wrote:
> I had this question, which I didn't really know where to ask, so I
> thought to begin at this mailing list.
>
> Very basicly said, I count the rows of a table which had approx 50000
> or more rows.
>
> The problem is, there is a notable difference in loading time with
> other pages. Is there a technique to estimate the number of rows
> instead of exactly couting them? So that it saves loading time.
How about:
SELECT COUNT(*) FROM table WHERE <criteria> ?
/Per Jessen, Zürich
--- End Message ---
--- Begin Message ---
On Sat, Jul 12, 2008 at 10:29 AM, tedd <[EMAIL PROTECTED]> wrote:
> At 9:36 AM +0200 7/12/08, Giulio Mastrosanti wrote:
>>
>> Hi,
>> I have a php page that asks user for a key ( or a list of keys ) and then
>> shows a list of items matching the query.
>>
>> every item in the list shows its data, and the list of keys it has ( a
>> list of comma-separated words )
>>
>> I would like to higlight, in the list of keys shown for every item, the
>> words matching the query,
>>
>> this can be easily achieved with a search and replace, for every search
>> word, i search it in the key list and replace it adding a style tag to
>> higlight it such as for example to have it in red color:
>>
>> if ( @stripos($keylist,$keysearch!== false ) {
>> $keylist = str_ireplace($keysearch,'<span style="color:
>> #FF0000">'.$keysearch.'</span>',$keylist);
>> }
>>
>> but i have some problem with accented characters:
>>
>> i have mysql with character encoding utf8, and all the php pages are
>> declared as utf8
>>
>> mysql in configured to perform queries in a case and accent insensitive
>> way.
>> this mean that if you search for the word 'cafe', you have returned rows
>> that contains in the keyword list 'cafe', but also 'café' with the accent. (
>> I think it has to do with 'collation' settings, but I'm not investigating at
>> the moment because it is OK for me the way it works ).
>>
>> now my problem is to find a way ( I imagine with some kind of regular
>> expression ) to achieve in php a search and replace accent-insensitive, so
>> that i can find the word 'cafe' in a string also if it is 'café', or 'CAFÉ',
>> or 'CAFE', and vice-versa.
>>
>> hope the problem is clear and well-explained in english,
>>
>> thank you for any tip,
>>
>> Giulio
>
> Giulio:
>
> Three things:
>
> 1. Your English is fine.
>
> 2. Try using mb_ereg_replace()
>
> http://www.php.net/mb_ereg_replace
>
> Place the accents you want to change in that and change them to whatever you
> want.
>
> 3. Change:
>
> <span style="color: #FF0000">'.$keysearch.'</span>'
>
> to
>
> <span class="keysearch">'.$keysearch.'</span>'
>
> and add
>
> .keysearch
> {
> color: #FF0000;
> }
>
> to your css.
>
> Cheers,
>
> tedd
I may be mistaken (and if I am, then just ignore this as ignorant
rambling), but I don't think he's wanting to replace the accented
characters in the original string. I think he's just wanting the
pattern to find all variations of the same string and highlight them
without changing them. For example, his last paragraph would look like
this:
[quote]
now my problem is to find a way ( I imagine with some kind of regular
expression ) to achieve in php a search and replace
accent-insensitive, so that i can find the word '<span
class="keysearch">cafe</span>' in a string also if it is '<span
class="keysearch">café</span>', or '<span
class="keysearch">CAFÉ</span>', or '<span
class="keysearch">CAFE</span>', and vice-versa.
[/quote]
The best I can think of right now is something like this:
<?php
function highlight_search_terms($word, $string) {
$search = preg_quote($word);
$search = str_replace('a', '[aàáâãäå]', $search);
$search = str_replace('e', '[eèéêë]', $search);
/* repeat for each possible accented character */
return preg_replace('/\b' . $search . '\b/i', '<span
class="keysearch">$0</span>', $string);
}
$string = "now my problem is to find a way ( I imagine with some kind
of regular expression ) to achieve in php a search and replace
accent-insensitive, so that i can find the word 'cafe' in a string
also if it is 'café', or 'CAFÉ', or 'CAFE', and vice-versa.";
echo highlight_search_terms('cafe', $string);
?>
Andrew
--- End Message ---