SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    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>
    ");
    
    } 
    
    ?>
    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).
    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 )

  2. #2
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


    [Edited by James Smith on 11-07-2000 at 05:06 PM]

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Come on guys?
    someone.. ?

    someone knows!!!! Help!

    Thanks,
    AJ

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have time to implement the actually code, but I could give you the idea, if you want
    Using an INSERT query instead of an UPDATE one, but first need to have a SELECT query to find if it's already in.

    So i could imagine that you need more if/else statement. Not so hard to implement though!
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •