Jump to content

[SOLVED] INDIVIDUAL ROW FROM QUERY?


rasta876

Recommended Posts

Hello all,

 

I used the code below to get the distinct names from my table

How do I get the individual rows after the query (for example the first or second one, etc..). Id like to echo the rows individually as I like.

 

The following code echoes all the names from the query

 

$query="SELECT DISTINCT name FROM myTABLE";

$results=mysql_query($query);

while($row=mysql_fetch_assoc($resluts)){

echo $row['name']"<br>";

}

 

this shows for example:  John

                                Susan

                                Kerry

 

What do I do if Id just like to echo one name from the query?

example: Susan

 

Link to comment
Share on other sites

Thank you for the quick reply, however im looking for a different result.

In my Table I have many rows with the same name (e.g.Susan many times), I used DISTINCT in my query to get rid of the repitition. Is it possible to echo one name from the results. For example referencing them by their position or something.

I cant set $name = 'Susan' because this value will occasionally change in the table when updated. The names will be replaced by new ones.

Id like to just get one.

Link to comment
Share on other sites

If I can filter say 50 names(including the same name more than once)  to just 5 names (no repitition) using DISTINCT and echo all five of them echo $row['name'] , how do I do the same thing but this time echo only one of the five without knowing the actual value, (something like echo $row + something unique for the each item)?

 

I can do this echo $row['name'];

to get  John

          Susan

          Kerry

          Tim

          Mika

 

I want to do something like this:

  echo $row[?????];

 

to get the second item which in this case would be:

              Susan

 

and then when my table content changes, the code

    echo $row[????];

 

would still be referring to the second item, which would be a different name this time around.

 

 

I hope you understand what I want

 

Link to comment
Share on other sites

Finally, I tried using mysql_data_seek and it worked. Thank you all for your effort.

 

$query="SELECT DISTINCT name FROM myTABLE";

$results=mysql_query($query);

mysql_data_seek($results,2 )                      //to get the second item.

while($row=mysql_fetch_assoc($resluts)){

echo $row['name']"<br>";

}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.