[PHP] Association Problem?
Wanted to see if anyone had any input on this. I have a recordset that is returned to me in my script. What I then would like to do is go through each row of the recordset and use the substr_count function to count the number of times a string appears in each row. Then I'd like to sort display the recordset based on how many times the string appeared in each row. Basically this is a very light search with a very quick dirty way to find relevancy. I've thought that I could just store the relevancy numbers in an array, but then how do I know which relevancy number goes with what row in the recordset? That's the association problem I'm talking about. Also, how would I then sort the recordset accordingly based on the relevancy array? I've been looking through the PHP documentation and can't quite get past this question. Anyone have any ideas? Thanks! Gabe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Association Problem?
On Mon, Jun 21, 2004 at 12:09:50PM -0400, Gabe wrote: Wanted to see if anyone had any input on this. I have a recordset that is returned to me in my script. What I then would like to do is go through each row of the recordset and use the substr_count function to count the number of times a string appears in each row. Then I'd like to sort display the recordset based on how many times the string appeared in each row. Basically this is a very light search with a very quick dirty way to find relevancy. I've thought that I could just store the relevancy numbers in an array, but then how do I know which relevancy number goes with what row in the recordset? That's the association problem I'm talking about. Also, how would I then sort the recordset accordingly based on the relevancy array? I've been looking through the PHP documentation and can't quite get past this question. Anyone have any ideas? Thanks! try array_multisort(): $search_str = 'abc'; $sort_array = array(); foreach ($recordset as $k = $v) { $sort_array[$k] = substr_count($v, $search_str); } array_multisort($sort_array, $recordset); - rob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Association Problem?
Gabe, Wanted to see if anyone had any input on this. I have a recordset that is returned to me in my script. What I then would like to do is go through each row of the recordset and use the substr_count function to count the number of times a string appears in each row. Then I'd like to sort display the recordset based on how many times the string appeared in each row. Basically this is a very light search with a very quick dirty way to find relevancy. I've thought that I could just store the relevancy numbers in an array, but then how do I know which relevancy number goes with what row in the recordset? That's the association problem I'm talking about. Also, how would I then sort the recordset accordingly based on the relevancy array? If the rows have a unique key / id, then you can always relate other data to each row by using that key. I've been looking through the PHP documentation and can't quite get past this question. Anyone have any ideas? Thanks! Since you're sorting the rows by relevancy IN PHP, you need to: - get the mysql rows into a PHP array - determin the relevancy of each row - resort the array by relevancy - print the contents I don't think the association is all that much of a worry. When you're creating your PHP array of mysql rows, just add in a Nth array element for relevancy, then sort the array on that. --- Justin French http://indent.com.au -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Association Problem?
Good idea storing it in an array. Sort the unique row ID and the count in the array and use asort(). Wanted to see if anyone had any input on this. I have a recordset that is returned to me in my script. What I then would like to do is go through each row of the recordset and use the substr_count function to count the number of times a string appears in each row. Then I'd like to sort display the recordset based on how many times the string appeared in each row. Basically this is a very light search with a very quick dirty way to find relevancy. I've thought that I could just store the relevancy numbers in an array, but then how do I know which relevancy number goes with what row in the recordset? That's the association problem I'm talking about. Also, how would I then sort the recordset accordingly based on the relevancy array? I've been looking through the PHP documentation and can't quite get past this question. Anyone have any ideas? Thanks! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php