4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: www.girls-on-bikes.com on June 01, 2003, 01:43:16 AM
-
Hello All,
I have a request for a mod.
It would be cool to be able to display a toplist of search keywords.
I actually want this for more internal usages so I can figure out what my users are searching for.
EDIT: This has been turned into an official mod located here:
http://www.4homepages.de/forum/viewtopic.php?t=6033
Thanks
-
I think the same and Top Categories is ok also. :wink:
-
It would be cool to be able to display a toplist of search keywords.
search strings are not stored in the database
-
search strings are not stored in the database
that's right, so, basicaly all u have to do ;) is create new table with two fields "name" and "count" for example.
then every time someone search for something u update that table...
*how to do that? I duno...*
-
I have thought about it and I'm actually going to attempt doing this script.
Granted I don't know enough about 4images, so it may not be a public mod, but I think I can write it.
-
OK Folks, here it is, the ugliest, most inefficient code you have ever seen.
I put this code inside search.html, and {lang_search} comes from:
http://www.4homepages.de/forum/viewtopic.php?t=5968
Also, I created 2 new tables for this job.
Any mad crazy 4image coders are welcome to take this idea and make a real mod out of it. Just wanted to share my <crappy> solution.
<?php
$search_phrase = "{lang_search}";
$search_phrase = str_replace("Search: ","",$search_phrase);
$search_terms = explode(" ", $search_phrase);
$db = mysql_connect("localhost", "gob", "************");
mysql_select_db("gob_gallery",$db);
$sql = "SELECT * FROM 4images_search_phrase WHERE phrase=\"".$search_phrase."\"";
$res = mysql_query($sql,$db);
$num_rows = mysql_num_rows($res);
if ($num_rows > 0) {
$row = mysql_fetch_array($res);
$count = $row["count"] + 1;
$sql = "UPDATE 4images_search_phrase SET count=\"".$count."\" WHERE phrase = \"".$search_phrase."\"";
$res = mysql_query($sql,$db);
}
else {
$sql = "INSERT INTO `4images_search_phrase` VALUES (\"".$search_phrase."\",1)";
$res = mysql_query($sql,$db);
}
foreach ($search_terms as $term) {
$sql = "SELECT * FROM 4images_search_terms WHERE term=\"".$term."\"";
$res = mysql_query($sql,$db);
$num_rows = mysql_num_rows($res);
if ($num_rows > 0) {
$row = mysql_fetch_array($res);
$count = $row["count"] + 1;
$sql = "UPDATE 4images_search_terms SET count=\"".$count."\" WHERE term = \"".$term."\"";
$res = mysql_query($sql,$db);
}
else {
$sql = "INSERT INTO `4images_search_terms` VALUES (\"".$term."\",1)";
$res = mysql_query($sql,$db);
}
}
mysql_close($db);
?>
-
ok, here is "adopted" for 4images classes version ;)
in search.php find:$sql = "SELECT m.image_id
add before: $sql = "UPDATE ".SEARCH_WORDS_TABLE."
SET count = count + 1
WHERE word LIKE '".addslashes(str_replace("*", "", $split_words[$i]))."'";
$site_db->query($sql);
if (!$site_db->affected_rows()) {
$sql = "INSERT INTO ".SEARCH_WORDS_TABLE."
(word, count)
VALUES
('".addslashes(str_replace("*", "", $split_words[$i]))."', 1)";
$site_db->query($sql);
}
in /includes/constants.php add this line:define('SEARCH_WORDS_TABLE', $table_prefix.'search_words');
create new table in the DB with name 4images_search_words
this will record each word that was searched for, and count how many times that word was searched. At the begining I was gonna just add an extra field in 4images_wordlist table, that would just store count of each word/keyword being searched, but then I realized that this way it wont count the words that are not in the DB....
-
Thanks for re-forming that into something usable ;)
Here is my finished product:
http://new.girls-on-bikes.com/search_stats.php
Edit:
I suppose I will embarrass myself even more and post up the code to print the stuff out. Hopefully somebody can take this and make a "real" mod.
<span class="title">Search Result Stats</span>
<hr size="1" />
<?php
$db = mysql_connect("localhost", "gob", "*********");
mysql_select_db("gob_gallery",$db);
$sql = "SELECT * FROM 4images_search_phrase ORDER BY `count` DESC";
$phrase_res = mysql_query($sql,$db);
$sql = "SELECT * FROM 4images_search_terms ORDER BY `count` DESC";
$terms_res = mysql_query($sql,$db);
$phrase_counts = array("");
$terms_counts = array("");
?>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td valign="top" width="50%">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td class="head1">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="head1" valign="top" width="90%">
Top Search Phrases
</td>
<td class="head1" valign="top" width="10%">Count</td>
</tr>
<tr>
<td class="row2" valign="top" width="90%">
<?php
for ($i=0;$row = mysql_fetch_array($phrase_res);$i++) {
print $row["phrase"]."<br>";
$phrase_counts[$i] = $row["count"];
}
?>
</td>
<td class="row2" valign="top" align="center" width="10%">
<?php
for ($i=0;$i<count($phrase_counts);$i++) {
print $phrase_counts[$i]."<br>";
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td valign="top" width="50%">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr>
<td class="head1">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="head1" valign="top" width="90%">
Top Search Terms
</td>
<td class="head1" valign="top" width="10%">Count</td>
</tr>
<tr>
<td class="row2" valign="top" width="90%">
<?php
for ($i=0;$row = mysql_fetch_array($terms_res);$i++) {
print $row["term"]."<br>";
$terms_counts[$i] = $row["count"];
}
?>
</td>
<td class="row2" valign="top" align="center" width="10%">
<?php
for ($i=0;$i<count($terms_counts);$i++) {
print $terms_counts[$i]."<br>";
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
mysql_close($db);
?>
-
Looks good!
I'll try it out, once my servers back up. :)
-
Please keep in mind this is not a public mod, it's my own <hacked> version. There would be some things you would need to do and change before you can use this, unless you can understand what my code says and you understand what needs to be changed ;)
Let me know if you would be interested and I can tell you what tables to add and what text to change.
-
inspired by www.girls-on-bikes.com got it working...now, just need some oppinium, should it be using paging system, and also, have ability sort words/phrases by name, or by count?
-
---> www.girls-on-bikes.com
Why not this mod is public for all?
You use 4mages script free no?
You request help to make it and V@no helps you.
You say "Any mad crazy 4image coders are welcome to take this idea and make a real mod out of it"
Well why you say this now "this is not a public mod" :?:
I want this mod :?
-
What I meant by a "public mod" is that in it's current form, it is not universal, meaning if you copied the code to your server, it would not work.
I am simply not familar enough with 4images to be able to incorporate it into a real mod, but I'm hoping some one who has coded in 4images will be able to.
Also, the script still has some bugs, and I'm working those out as they arise.