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
https://forums.phpfreaks.com/topic/130274-solved-individual-row-from-query/
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.

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

 

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>";

}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.