Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find specific row in the table 1

Status
Not open for further replies.

ilyawizard

Programmer
Feb 3, 2006
3
US
I have a table full of articles. Each article is categorized by disease. Also I have a page that needs randomly choose an article with specific disease. First I'm using COUNT() to find out how many articles of the specific category I have. Then I randomly generate the namber between 1 and COUNT(). And then when it gets tricky. Is there a way to get an article right away if I know the number in the order. Right now I have a for loop that fetches an array number of times random number was generated:

for ($i=1;$i<$rnd;$i++){
$info=@mysql_fetch_array($query);
}

DO you know any faster way?
 
if you know the row number, you can use mysql_data_seek

why no just do a simple

select * from table where cat_id=$some_value order by rand() limit 1

which would get one random row from a specific category

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Thank you, didn't know about the rand() in sql. That'll do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top