merck_delmoro Posted May 6, 2009 Share Posted May 6, 2009 Example Record in the DataBase: Cat Dog Mouse I want to output : The Dog is Located at # 2 Link to comment https://forums.phpfreaks.com/topic/157016-solved-q-locating-the-position-of-records-in-the-database-using-php/ Share on other sites More sharing options...
taith Posted May 6, 2009 Share Posted May 6, 2009 easiest way is to put an auto_increase'ing number in your table... basically every entery takes the next sequencial number... Link to comment https://forums.phpfreaks.com/topic/157016-solved-q-locating-the-position-of-records-in-the-database-using-php/#findComment-827187 Share on other sites More sharing options...
merck_delmoro Posted May 6, 2009 Author Share Posted May 6, 2009 I've done it by my self haha this is the code I've made $query=mysql_query("SELECT * FROM animals"); while($row = mysql_fetch_array($query) and $row['animal'] !="dog") { $count+=1; } echo print "The Dog is Located at # ".$count+1; Link to comment https://forums.phpfreaks.com/topic/157016-solved-q-locating-the-position-of-records-in-the-database-using-php/#findComment-828022 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Does animals have an ID field? Simpler and faster: $result = mysql_query("SELECT id FROM animals WHERE animal = 'dog' LIMIT 1"); $row = mysql_fetch_assoc($result); echo $row['id']; Link to comment https://forums.phpfreaks.com/topic/157016-solved-q-locating-the-position-of-records-in-the-database-using-php/#findComment-828024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.