6 Replies - 979 Views - Last Post: 07 March 2010 - 03:19 AM Rate Topic: -----

#1 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Help with a check progress function

Posted 07 March 2010 - 03:01 AM

G,day all, i am making a php game engine, i have a feature i want, i have it all planned, ok i have it all done. Except i need a function, i have it done except one bit. Here is my sql structure for the tabe. Id
u_id
p_id
level
ok, here is my query
$point = $db->query("SELECT p.* FROM points p WHERE p.u_id='{$f['userid']}'");

now it all works fine except for after i gain the first point. Now i need the query to only grab 1 of each p.p_id. Can any one please help.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with a check progress function

#2 Skaggles   User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 255
  • View blog
  • Posts: 641
  • Joined: 01-March 09

Re: Help with a check progress function

Posted 07 March 2010 - 03:09 AM

Adding 'LIMIT 1' to the SQL query will only retrieve the first result, if that's what you wanted.
Was This Post Helpful? 0
  • +
  • -

#3 Valek   User is offline

  • The Real Skynet
  • member icon

Reputation: 544
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Help with a check progress function

Posted 07 March 2010 - 03:11 AM

Actually, I believe what you're looking for is SELECT DISTINCT. This will return only distinct rows which, since you're sorting by u_id, means that for that u_id you'll only get one row of each p_id (unless for some reason you have a row with the same u_id and p_id as another with a different level, but I find that very highly unlikely).

$point = $db->query("SELECT DISTINCT p.* FROM points p WHERE p.u_id='{$f['userid']}'");

This post has been edited by Valek: 07 March 2010 - 03:11 AM

Was This Post Helpful? 0
  • +
  • -

#4 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Re: Help with a check progress function

Posted 07 March 2010 - 03:12 AM

Actually, that is what i sorta want. I need it to only select 1 of each p.p_id

Actually, that is what i sorta want. I need it to only select 1 of each p.p_id
Was This Post Helpful? 0
  • +
  • -

#5 Valek   User is offline

  • The Real Skynet
  • member icon

Reputation: 544
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Help with a check progress function

Posted 07 March 2010 - 03:16 AM

LIMIT 1 wouldn't do it then, as it would only return one row period. SELECT DISTINCT should cover your needs.
Was This Post Helpful? 0
  • +
  • -

#6 aaron1178   User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 170
  • View blog
  • Posts: 1,311
  • Joined: 22-October 08

Re: Help with a check progress function

Posted 07 March 2010 - 03:17 AM

Ok, so if i have 2 entrys in my database with p.u_id = 1. That query will get both entrys as long as the p.p_id is not the same as the other?

Ok, so if i have 2 entrys in my database with p.u_id = 1. That query will get both entrys as long as the p.p_id is not the same as the other?
Was This Post Helpful? 0
  • +
  • -

#7 Valek   User is offline

  • The Real Skynet
  • member icon

Reputation: 544
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Help with a check progress function

Posted 07 March 2010 - 03:19 AM

That is correct, yes. For DISTINCT to block off a row, it has to be identical in every selected column to another selected row.

This post has been edited by Valek: 07 March 2010 - 03:19 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1