Hi.
I am trying to make a 'TOP 100' keywords script for my search engine, which launches in a few months.
I have a system in PHP + MySQL which logs all teh keywords that have been searched for, and adds to their popularity every time they are searched for.
Now, I would like to display a 'TOP 100' which allows users to scroll through all the top searches, ordered by popularity.
This is easy enough, as it is just a matter of limiting it to 100, and 'ORDER BY' popularity. I can do that easily.
But what I would like to do, is display a sort of results page menu:
1-19 20-39 40-59 60-79 80-100
I can do a page system easily, with values of Page 1, Page 2, Page 3, Page 4 etc...
But I would like to know how to produce the correct numbers i.e. 1-19, using the least code possible.
What I have so far is: (it probably needs scraping, I haven't been doing PHP for long, and it shows)
You can see how I have tried..Code:<table> <?php mysql_connect("localhost", "root", ""); mysql_select_db("eliter"); $limit = 20; $numrows = 100; if (!isset($offset)) $offset=0; $result = mysql_query("SELECT * FROM keywords ORDER BY popularity DESC LIMIT $offset, $limit"); echo("<tr><td>"); while ( $details = mysql_fetch_array($result) ) { $keyword = $details["keywords"]; echo(" <font class=twelvept><b>$num.</b> <a href='http://www.eliter.com/servlet/search?query=$keyword&where=web'>$keyword</a></font><br> "); } if ($numrows > $limit) { // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } print '<br><font class=tenpt>Top 100 Keywords: '; //Create the links for ($i=1; $i <= $pages; $i++) { // loop thru $newoffset=$limit*($i-1); if ($newoffset != $offset) { printf(' <a href="%s?offset=%s">%s</a> ', $PHP_SELF, $newoffset, $i, "</font>"); } else { $lastresult=($newoffset-1)+$limit; $firstresult = $lastresult-19; print " <font class=tenptbold> $firstresult - $lastresult </font>"; } } } ?> </table>
Also, what I am having a problem with, is giving each result a number according to where they are in the top 100.
I tried the for statement, but couldn't get it to work with the while statement.
CAn anyone offer any help?
Thank alot.
AJ



)

Bookmarks