Reputation: 41
I currently have a buddy system that requires a lot of queries and has a lot of users. My method of searching for a specific user worked for a while until the amount of entries started to get into the 10s of thousands. The way I currently search for a user is like this:
$results = mysql_query("SELECT * FROM Info");
while($row = mysql_fetch_array($results)){
$ignFromDB = $row['IGN'];
if($ignFromDB == $ign){
$friendsFromDB = $row['Friends'];
$frArr = explode(':', $friendsFromDB);
return $frArr;
}
}
Since I now need to search through 10s of thousands of entries it becomes a very inefficient and slow approach. As a way of solving this I decided to only have one search request per user: At startup they would request their entry index and then would send a request with that index so I wouldn't need to loop. I could just select the entry with that index. Only problem is I have very little knowledge of MySQL and I need to know how to do this. Any help would be greatly appreciated!
Upvotes: 0
Views: 39
Reputation: 553
Try this code
$results = mysql_query("SELECT * FROM Info WHERE IGN='$ign'");
while($row = mysql_fetch_array($results)){
$friendsFromDB = $row['Friends'];
$frArr = explode(':', $friendsFromDB);
return $frArr;
}
Upvotes: 0
Reputation: 46900
Wow so much for just a WHERE
clause. You are going to market, buying all the apples and then coming back home and then start checking which of the thousands do you really need. Why not simply tell the shopkeeper your requirement and get only the required apple. Imagine the cost! You just need
SELECT * FROM Info WHERE IGN='$ign'
And that's it
Must Read: Warning About SQL Injection
Upvotes: 2