Recent Searches - Help please. (my first post!)
Posted: Thu Nov 18, 2010 11:56 pm
Hello All. I hope I am doing this right. This is my very first post here and I am pleased to join the PHP DN forum. I am a web designer who has recently learned PHP (my first language other than css/html of course), and I feel absolutely addicted to learning. I've actually done alright for myself since I learned how to create PHP Pages on the fly already and I just started learning 3 days ago
But I'm a little stuck and need a little help. I promise 100% that I have done TONS of research about this, just can't find my answer. Anything is appreciated, and thank you in advance!
I am trying to create a function that will echo the most recent searches on my search engine. However here is what I need to achieve:
1. Don't echo duplicate recent searches. Every search made is logged to my database, including duplicates.
2. They should not exceed a certain amount of characters as I have these recent searches displayed on a small horizontal bar that goes across at the absolute top of my search engine. Too many characters might make it look bad (small monitors, small resolutions), especially because I have additional links on the far right of the horizontal bar. So in case somebody makes a query for a very long phrase, don't echo that phrase.
3. However, there should always be enough recent searches so that it doesn't look too empty! So if there's 3 searches that are all 1 letter long (hypothetically) make sure to echo additional recent searches!
4. Only repopulate (is that the right word?) the recent searches every minute or so. I will be getting very heavy traffic and don't want to put unnecessary stress on the server.
5. Finally, don't echo recent search queries that would not return a result on the search engine. (My search log has a field titled "results" which lists how many results the search query returned)
Here's what I've started with (apparently I did the implode incorrectly as it does echo the recent searches but without the glue).
function recent_searches(){
$query = mysql_query("SELECT search_string FROM search_log ORDER BY datetime DESC LIMIT 3");
while($row = mysql_fetch_row($query)){
echo implode(", ",$row);
}
}
recent_searches();
I know this is not complete. But I don't know how close I am either. I'm not even sure how difficult this is. But once again, ANY help in the right direction is a major assistance to me while I continue to explore the depths of PHP! ^_^ Thank you all for reading.
I am trying to create a function that will echo the most recent searches on my search engine. However here is what I need to achieve:
1. Don't echo duplicate recent searches. Every search made is logged to my database, including duplicates.
2. They should not exceed a certain amount of characters as I have these recent searches displayed on a small horizontal bar that goes across at the absolute top of my search engine. Too many characters might make it look bad (small monitors, small resolutions), especially because I have additional links on the far right of the horizontal bar. So in case somebody makes a query for a very long phrase, don't echo that phrase.
3. However, there should always be enough recent searches so that it doesn't look too empty! So if there's 3 searches that are all 1 letter long (hypothetically) make sure to echo additional recent searches!
4. Only repopulate (is that the right word?) the recent searches every minute or so. I will be getting very heavy traffic and don't want to put unnecessary stress on the server.
5. Finally, don't echo recent search queries that would not return a result on the search engine. (My search log has a field titled "results" which lists how many results the search query returned)
Here's what I've started with (apparently I did the implode incorrectly as it does echo the recent searches but without the glue).
function recent_searches(){
$query = mysql_query("SELECT search_string FROM search_log ORDER BY datetime DESC LIMIT 3");
while($row = mysql_fetch_row($query)){
echo implode(", ",$row);
}
}
recent_searches();
I know this is not complete. But I don't know how close I am either. I'm not even sure how difficult this is. But once again, ANY help in the right direction is a major assistance to me while I continue to explore the depths of PHP! ^_^ Thank you all for reading.