Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 30 Jan 2002, 19:14
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Associative arrays

Hi. Where could I find an exaustive help with examples about multi-dimensional arrays ?
Actually I would - for a hack - store in memory some fields of a table of VB (user), to make some intensive operation without loading the db.
I thought a 2D array like this: $userArray[][]
Would use the two index, first as userid or other incremental value, second as the fields in the table.
For instance:

$userArray[][name]=$user[username]
$userArray[][mail]=$user[email]
... etc. in a cycle after a db fetch, but of course it doesn't work this way...
Neither with an explicit first index as variable.

Do you have some example to load table in array with more values than the (key,value) as in php.net ?

Thanks a lot.
Bye
Reply With Quote
  #2  
Old 30 Jan 2002, 23:30
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
You do not want to do this. You will cram your RAM. (I made a rhym! )

It's better to build a query, then skip around the recordset using mysql_data_seek().
Reply With Quote
  #3  
Old 31 Jan 2002, 09:54
Chen's Avatar
Chen Chen is offline
 
Join Date: Sep 2001
Where's the ryhm?
__________________
Chen Avinadav
Formerly vBulletin.org Owner and Founder

chen@avinadav.com
Reply With Quote
  #4  
Old 31 Jan 2002, 10:17
Jawelin Jawelin is offline
 
Join Date: Nov 2001
... cram .... RAM ... :greedy:

So it would be more efficient go back & forth through the recordset instead of loading data into Ram ?
Isn't it too heavy to mySQL engine ?

I should compare new users data with old ones.
If I had 'N' news (let's say 10 at a time) and 'T' total old users (let's say +3000...), the complexity of the check should be:
N*T = 30.000 seeks on DB !!!!
:noid:

Any idea ?

Thanks.

P.S.: and what about using mysql_fetch_array() or mysql_fetch_row() just after the seek ? Either which ?

Last edited by Jawelin : 31 Jan 2002 at 10:21.
Reply With Quote
  #5  
Old 31 Jan 2002, 18:55
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
I'm not sure about mySQL load for mysql_fetch_array() vs mysql_fetch_row(), but the fetch_array will take up more memory (not much).

What is the hack for?
How often will this be run?

How much data are you pulling from the DB?
Do you need to pull all the fields, or just a few?
Can you throw any of the logic at the DB or does it need to be done in PHP?

Compare this...
30,000 DB seeks
... or ...
30,000 * (number of fields) demensional array
Reply With Quote
  #6  
Old 01 Feb 2002, 12:29
Chen's Avatar
Chen Chen is offline
 
Join Date: Sep 2001
That is the weakest rhyme I've ever heard.
__________________
Chen Avinadav
Formerly vBulletin.org Owner and Founder

chen@avinadav.com
Reply With Quote
  #7  
Old 01 Feb 2002, 15:36
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
*sigh* well, I tried
Reply With Quote
  #8  
Old 01 Feb 2002, 16:50
Jawelin Jawelin is offline
 
Join Date: Nov 2001
Originally posted by Mark Hensler
I'm not sure about mySQL load for mysql_fetch_array() vs mysql_fetch_row(), but the fetch_array will take up more memory (not much).

What is the hack for?
How often will this be run?
[...]
Well. I was trying to do myself an enhanced user moderation queue, mainly to findout potential dupe users when moderating new ones.
You can check here the original input, but would try to solve myself as far as i could.

By now I added a new action to admin/user.php like 'finddupe', called from the user moderation page.

Actually I would need to load in memory almost 3-4 columns of the user table as I should compare the single metaphone() each others, measuring the levenshtein() distance between, for example, usernames/emails/ips/password-md5-hash (identical, of course), and so on.
This reason I though to memory as mySQL couldn't do anything itself.

Frequency: well, about once/twice a day, the times I moderate new users...
Do you think an array like this should overload the system ?

P.S.: anyway, any 2D arrays example ??? :supwink:

Thanks, poet!!! :china:
Reply With Quote
  #9  
Old 01 Feb 2002, 22:01
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Why are your that paranoid? That seems like overkill.

Anyway.. Your right, you couldn't do this in mySQL. I've never loaded an array of that size. I'm not sure what that would do to your system.

Some thoughts...
You don't have to calculate the metaphone() for each search. Instead, calculate it once for all existing users, and when new users register. Store the value in another field in the DB. Then you could use a simple query to test the metaphone() for new users.

The levenshtein is trickier, as you can't preproccess anything and store it in the DB.

What did you want to do to the IP? levenshtein()? You may be able to do something similar by using wildcards in mySQL. For example, most dialups will only vary in the last 2 octets.


Just some thoughts.
Reply With Quote
  #10  
Old 01 Feb 2002, 22:13
Jawelin Jawelin is offline
 
Join Date: Nov 2001
They are all parameters that - took together - can build a complex profile about a dupe user.

Paranoid? Yeah! I saw for months people subscribing again and again just because they wouldn't remember the password...
I explained well talking about the hack I linked to above.
Thanks, hwr.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 18:49.

Layout Options | Width: Wide Color: