Jump to content

Recommended Posts

Any ideas on how to make this script work on my site after the database is connected?

im lost

what must i do?

 

 

<?


$txt='<p>The tag cloud using a Mysql connection</p><p>';

//As tag clouds are most of the time generated from the results contained inside a database, this script is using a database:

$db=mysql_connect('localhost','yourusername','yourpasswd') or die(mysql_error());
mysql_select_db('yourbase');


//First off, let's create a table with few search queries:

mysql_query("CREATE TEMPORARY TABLE searchterms (term VARCHAR(150) NOT NULL PRIMARY KEY,nbsearches BIGINT UNSIGNED NOT NULL DEFAULT 1,datesearch DATE NOT NULL)",$db) or die(mysql_error());

//Let's insert some data:
mysql_query("INSERT INTO searchterms SET term='1st term',nbsearches=20,datesearch='2007-11-10'",$db);
mysql_query("INSERT INTO searchterms SET term='2nd term',nbsearches=40,datesearch='2007-11-11'",$db);
mysql_query("INSERT INTO searchterms SET term='3rd term',nbsearches=25,datesearch='2007-12-10'",$db);
mysql_query("INSERT INTO searchterms SET term='4th term',nbsearches=200,datesearch='2007-12-01'",$db);
mysql_query("INSERT INTO searchterms SET term='5th term',nbsearches=2,datesearch='2007-11-02'",$db);
mysql_query("INSERT INTO searchterms SET term='6th term',nbsearches=45,datesearch='2007-12-10'",$db);
mysql_query("INSERT INTO searchterms SET term='7th term',nbsearches=120,datesearch='2007-12-11'",$db);
mysql_query("INSERT INTO searchterms SET term='8th term',nbsearches=767,datesearch='2007-11-12'",$db);
mysql_query("INSERT INTO searchterms SET term='9th term',nbsearches=220,datesearch='2007-12-12'",$db);
mysql_query("INSERT INTO searchterms SET term='10th term',nbsearches=10,datesearch='2007-11-13'",$db);
mysql_query("INSERT INTO searchterms SET term='11th term',nbsearches=520,datesearch='2007-12-14'",$db);

//we assume we have a table containing the searched terms along with the number searches for each one:
//we create a temporary table out of it; we filter the eldest ones (we take the 100 most recent):
mysql_query("CREATE TEMPORARY TABLE tempsearch SELECT term,nbsearches FROM searchterms ORDER BY datesearch DESC LIMIT 100",$db) or die(mysql_error());

//Create another table from that temporary one to sort the results and extract the wanted amount (10):
mysql_query("CREATE TEMPORARY TABLE tempsearchsorted SELECT term FROM tempsearch ORDER BY nbsearches DESC LIMIT 10",$db) or die(mysql_error());

//Take the maximum number of searches for a term
$q=mysql_query("SELECT max(nbsearches) FROM searchterms,tempsearchsorted WHERE tempsearchsorted.term=searchterms.term",$db) or die(mysql_error());
$sum=mysql_result($q,0);


//Sort by name
$q=mysql_query("SELECT searchterms.term,searchterms.nbsearches FROM searchterms,tempsearchsorted WHERE tempsearchsorted.term=searchterms.term ORDER BY searchterms.term ASC",$db) or die(mysql_error());

while($l=mysql_fetch_assoc($q))
{

$txt.= '<a href="/yourpage.php?item='.urlencode($l['term']).'" style="font-size:'.($l['nbsearches']/$sum + 0.9).'em">'.$l['term'].'</a> ';

}

$txt.='</p>';

echo $txt;

mysql_close($db);

?>

Link to comment
https://forums.phpfreaks.com/topic/83748-solved-integration-of-search-cloud/
Share on other sites

sorry for the lack of information.

it outputs this

 

The tag cloud using a Mysql connection

 

10th term 11th term 1st term 2nd term 3rd term 4th term 6th term 7th term 8th term 9th term

 

I dont understand how i can get it to show search results from my site.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.