Hey guys.
I have a query about one of my scripts..
I am creating a metasearch engine, and the main script is done as a servlet.
I am also creating a keyword management system, where I can view all the keywords that are searched for, and their popularity (programmed in PHP + MySQL). Now, I have done nearly all of the system, but not the script that logs new keywords and updates the popularity of others.
What I have done on this script so far is:
Now, this is all very well, and it updates the popularity correctly, and it works fine. However, the problem is, this only works for keywords that already exist (keywords that have already been searched for, and therefore are in the database).Code:<?php // if the keyword exists if (isset ($keyword) ) { mysql_connect("localhost", "root", ""); mysql_select_db("eliter"); // find the popularity of the keyword $selectpop = mysql_query("SELECT popularity FROM keywords WHERE keywords='$keyword' "); while ( $details = mysql_fetch_array($selectpop) ) { $popularity = $details["popularity"]; // new popularity = old popularity plus one $newpopularity = $popularity + 1; mysql_query("UPDATE keywords SET popularity='$newpopularity' WHERE keywords='$keyword' "); echo (" <font size=1 face=verdana color=c0c0c0> The keyword $keyword has been adjusted.</font><br> "); } } else { echo (" <font size=1 face=verdana color=c0c0c0> There was an <b>error</b> adding the keyword into the database.</font> "); } ?>
So what I would like, is a section of code that checks the database to see if the keyword exists, and if it doesn't exist, it adds it to the database, and assigns it with a popularity of 1 (because it is the first time someone has searched for it).
And of course, if it does exist, it proceeds with the code that I pasted above, which works fine.
Can anyone PLEASE help me with this?!
Thanks in advance guys!
Cheers-
AJ O'Connell
(oh, and the way i will run this script, is as an include on the main results page, and i have the output merely for test purposes at the moment, so don't question me on that)



)



Bookmarks