Jump to content


Select certain rows


6 replies to this topic

#1 ktd

    * Something Ain't Right *

  • Members
  • PipPipPip
  • 549 posts
  • Gender:Male

Posted 03 March 2006 - 07:58 PM

Okay, This is harder then the title sounds.

I have so far done this:
  $query = "SELECT * FROM skills WHERE pid=".$id;
  $result = mysql_query($query) OR die(mysql_error());
  while($row  = mysql_fetch_array($result))
  {

Now the question is:
How do I get a certain field with a certain ID. I'm going to explain this as best as possible.

I have these rows:

| id | pid | xp | level | sid

Now, I need to show all the rows with the pid that equals but one at a time by using sid. Now how would I do that?

#2 rik

    Young Padawan

  • Members
  • Pip
  • 8 posts
  • Location:England

Posted 03 March 2006 - 08:40 PM

echo ($row["id"]);




change ID accordingly

#3 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 04 March 2006 - 01:23 AM

well you need to get the query right first:

$query = "SELECT * FROM `skills` WHERE pid = '$id'";

but with echoing out the rows i do them as $row[0] and so on:

id = $row[0]
pid = $row[1]
xp = $row[2]
level = $row[3]
sid = $row[4]


so if you want to echo out the xp row it would be $row[2]

Edited by deadly, 04 March 2006 - 01:24 AM.


#4 ktd

    * Something Ain't Right *

  • Members
  • PipPipPip
  • 549 posts
  • Gender:Male

Posted 04 March 2006 - 09:22 AM

You guys didn't see the problem. You went back to basics. I don't want to print out the all the XP rows that have pid as 1 for example. I want to print them 1 by 1.

I just did 21 querys for each sid which should work. Is there a way to check if a certain row doesn't exsits? Like if I did
$query = "SELECT * FROM `skills` WHERE pid = '$id' AND sid='1'";

And then check to see if there isn't a sid with 1?

#5 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 06 March 2006 - 04:02 PM

I'm having some trouble understanding. Is this what you want?

SELECT * FROM skills WHERE pid = '$id' ORDER BY sid

This query will display all the sid entries that have the pid = $id.

It might be easier to understand if we knew the use for the fields. Like wth is pid? I'm thinking pid is Player ID and sid is Skill ID or something. Looks like you're making a game.

BTW, queries run WAY faster if you don't use *, instead select all the fields like this:

SELECT id, pid, xp, level, sid FROM skills

Edited by Lang, 06 March 2006 - 04:03 PM.


#6 ktd

    * Something Ain't Right *

  • Members
  • PipPipPip
  • 549 posts
  • Gender:Male

Posted 06 March 2006 - 09:00 PM

Nope, That's not what I wanted. I need to select 1 field that would always be the same. And another one that increases by 1 by 1.

I got it all figured out now. I just did a loop and got it running okay. Thanks for the help (or attempt to help) :unsure:

#7 liveman

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Location:New Jersey

Posted 07 March 2006 - 06:54 AM

Is this just selecting one row? if it is save yourself the trouble and instead of
  while($row = mysql_fetch_array ...
have it
 $new = mysql_query($query);
  $row = mysql_fetch_row($new);
the while statement isnt needed nore the "{" "}"

Hope that helps!


Click Here to read more about "mysql_fetch_row();"

Edited by liveman, 07 March 2006 - 06:55 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users