Unix Technical Forum

compare

This is a discussion on compare within the MySQL forums, part of the Database Server Software category; --> How can I stop a function in PHP? When comparing data I want to stop the function on a ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:34 AM
Piet
 
Posts: n/a
Default compare

How can I stop a function in PHP?

When comparing data I want to stop the function on a hit.



Function compare($data) {

For ($n=1; $n<=10000; $n++) {

For ($m=1; $m<=10000; $m++) {

If $data[$n]==data[$m] {

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 07:34 AM
Jerry Stuckle
 
Posts: n/a
Default Re: compare

Piet wrote:
> How can I stop a function in PHP?
>
> When comparing data I want to stop the function on a hit.
>
>
>
> Function compare($data) {
>
> For ($n=1; $n<=10000; $n++) {
>
> For ($m=1; $m<=10000; $m++) {
>
> If $data[$n]==data[$m] {
>
> .
>
> Exit function, or exit for.. --- but how?
>
> }
>
> }
>
> }
>
> How can I avoid comparing 10000 * 10000 times?
>
>
>
> Thanks
>
>
>
> Piet
>
>


Among other ways - return can return from a function; break can break a loop.
Or you can use a flag variable to indicate you wish to exit the loop.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 07:34 AM
Jerry Stuckle
 
Posts: n/a
Default Re: compare

Piet wrote:
> How can I stop a function in PHP?
>
> When comparing data I want to stop the function on a hit.
>
>
>
> Function compare($data) {
>
> For ($n=1; $n<=10000; $n++) {
>
> For ($m=1; $m<=10000; $m++) {
>
> If $data[$n]==data[$m] {
>
> .
>
> Exit function, or exit for.. --- but how?
>
> }
>
> }
>
> }
>
> How can I avoid comparing 10000 * 10000 times?
>
>
>
> Thanks
>
>
>
> Piet
>
>


(Ignore previous message - though I was in a different group).

Depends in what language you're using to program. Check newsgroup for the
language you're using.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 07:34 AM
Bill Karwin
 
Posts: n/a
Default Re: compare

Piet wrote:
> How can I stop a function in PHP?
>
> When comparing data I want to stop the function on a hit.
>
>
>
> Function compare($data) {
>
> For ($n=1; $n<=10000; $n++) {
>
> For ($m=1; $m<=10000; $m++) {
>
> If $data[$n]==data[$m] {


Seems like you could load the data into a MySQL table, and use:

SELECT val, COUNT(val)
FROM mytable
GROUP BY val
HAVING COUNT(val) > 1

This will be very quick if you put an index on val.

(I know this isn't answering your question directly, but this is a MySQL
newsgroup, so I'm trying to use MySQL in the solution! ;-)

Regards,
Bill K.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:16 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com