i am trying to create a listing of the top searches.
i have a table that has: search date user
What I want is a listing that takes all the search words and says, the top searches are: 1. abc (10) --- number represents how many times 2. def (8) 3. ghi (4)
Any help on that?
thanks guys..
create a db table. 'searches'
fields;
search_id (int) autoinc term (char(80)) cnt (int)
then, everytime someone runs a search, run a select query to see if it has allready been searched for, if so, add 1 to the cnt field, if not, add a new 'term'
heres what i have...
$sum2 = mysql_query("SELECT search,count(search) AS total FROM searchcount GROUP BY search ORDER BY total DESC Limit 5"); for ($x=0; $x<mysql_num_rows($sum2); $x++) { $total2 = mysql_fetch_assoc($sum2); foreach($total2 as $val2) { echo ' <tr class="newsItem'.($i++ % 2 ? '1':'2').'"> <td>$val2</td>'; } } echo"</tr>";
when i do the select in phpmyadmin it works.. but when i do it on the site, i get a list of $val2
Originally posted by joey3002 heres what i have... $sum2 = mysql_query("SELECT search,count(search) AS total FROM searchcount GROUP BY search ORDER BY total DESC Limit 5"); for ($x=0; $x<mysql_num_rows($sum2); $x++) { $total2 = mysql_fetch_assoc($sum2); foreach($total2 as $val2) { echo ' <tr class="newsItem'.($i++ % 2 ? '1':'2').'"> <td>$val2</td>'; } } echo"</tr>"; when i do the select in phpmyadmin it works.. but when i do it on the site, i get a list of $val2 [/B]
Originally posted by joey3002 heres what i have...
when i do the select in phpmyadmin it works.. but when i do it on the site, i get a list of $val2 [/B]
because look at your code, you are echoing $val2
variables aren't parsed when in sigle quotes.
try this;
echo ' <tr class="newsItem'.($i++ % 2 ? '1':'2').'"> <td>'.$val2.'</td>'; }
thanks.. getting there, i have info but now the info is in a new td each line..
like:
abc 25 def 15
notice how its a new line.. i would love it to be: abc 25 def 15
thanks guys
...did i read his post wrong? oops. lol
$sum2 = mysql_query("SELECT search,count(search) AS total FROM searchcount where kind = 1 AND search <> '' GROUP BY search ORDER BY total DESC Limit 5"); for ($x=0; $x<mysql_num_rows($sum2); $x++) { echo ' <tr class="newsItem'.($i++ % 2 ? '1':'2').'"> '; $total2 = mysql_fetch_assoc($sum2); foreach($total2 as $val2) { echo'<td>'.$val2.'</td>'; } } echo"</tr>";
resolved.. thanks