Jump to content

Displaying 1 of multiple

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
Okay well i am making logs. Where it log's the person's ip who logs in. Well everytime they click Main.php it log's their ip. so when you go to view the logs it shows alot of that 1 user with the same ip..
What i want it to do is when you view the logs i want it to check and see if the user has the same ip. if not it will show both ip's.

Like for example:
whitey (username)
127.126.0.0 (IP)

and it has multiple of those i just want it to display it once..

but if it has a different ip display both of those..
like for example:
whitey
127.126.0.0
127.121.1.0

if you could just help me start this i can finish it. Thanks :)

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
By storing your logs in a delimited format, you can dump the contents into an array. From there, its simple.

#3
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
guessing its MySQL...

Just use

Quote

SELECT DISTINCT `username` FROM ....
then under that

Quote

SELECT `IP` FROM table WHERE `username`='$username'

its actually exactly what I had a problem with... and that code fixed it, if you want to see my example, go to V.B. login as the sample account or make an account, launch the browser, then click history.
What it does is looks through the `history` table, which has "id, date, url, member" as the format, then SELECT DISTINCT date WHERE username=username
that will echo the date, then SELECT URL WHERE date=date and username=username..

all from one table, yet groups them by date, just like you want to group them by username, correct?

Edited by phpforfun, 29 June 2008 - 10:24 AM.

Checkout my new forum! http://adminreference.com/

#4
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
yea my friend gave this as well.. Thanks man it works great!

#5
phpforfun

phpforfun

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,236 posts
no problem sir :) You should thank Jordan and John for showing me, lol
Checkout my new forum! http://adminreference.com/

#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
The SQL above will work fine, you can also do what John suggested and use an array. This function: array_unique will remove duplicates.

Quote

Takes an input array and returns a new array without duplicate values.
Note that keys are preserved. array_unique() sorts the values treated as string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.





It depends on where you want to do the removal of duplicates, in the DB or in PHP. Typically, using PHP is faster but in this case I'm not sure if you will see much difference. Perhaps I should do a benchmark on it and blog about it? :)