Need Urgent Help - Will Pay for SQL Query/Simple PHP Script ASAP!

Discussion in 'MySQL' started by charless, Jul 24, 2007.

  1. #1
    SQL structure looks as follows:

    table (main_keywords)

    keyword_id, domain_id, user_id, keyword, redir
    1, 1, 125, keyword 1, http://site.com/keyword-1
    2, 1, 125, keyword 2, http://site.com/keyword-2

    table (domains)

    domain_id, user_id, domain, username, template, ip_based, redir, keyword
    1, 125, http://domain.info, user, 1, 1, http://site/keyword-1, keyword 1

    I basically want to pull the redir from the table (domains) and change all of the corresponding entries in table (main_keywords)..corresponding meaning same domain_id. I have over 70,000 entries per server over 5 servers.

    Summary: Set table(main_keywords) redir for each keyword to match the domain redir URL found in table(domains).

    I have about 200-300 sites per server. 300-400 keywords per site. I basically want to change the keyword redirect pages to be the same as the main index page redirect url for each site. It's hard to explain but I'm willing to pay for this simple php script/sql query!

    My aim is charlesgmullen, e-mail =

    Thanks
     
    charless, Jul 24, 2007 IP
  2. supamanjon

    supamanjon Peon

    Messages:
    586
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I hope someone helsp you out on that
     
    supamanjon, Jul 24, 2007 IP
  3. bluegrass special

    bluegrass special Peon

    Messages:
    790
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm not sure which one you want from domains, but it would look something like this: (I haven't tested this in MySQL as I use MSSQL)

    UPDATE main_keywords SET redir = (SELECT domains.redir FROM domains WHERE main_keywords.domain_id = domains.domain_id)

    If you meant you wanted to get the domain, not the redir, from table(domains) then just swap domains.domain for domains.redir
     
    bluegrass special, Jul 24, 2007 IP
  4. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    I think you want to change the values in "main_keywords" of "domain_id" using the values in "table domains".
    Try this:
    (Please backup the databases first)
    <?php
    //connect to DB
    $mt= "main_keywords";
    $md= "domains";

    $q= mysql_query("SELECT domain_id,redir FROM $md");
    $num= mysql_numrows($q);
    $i=0;
    while($i<$num){
    $red= mysql_result($q, $i, "redir");
    $di= mysql_result($q, $i, "domain_id");
    $sql= mysql_query("UPDATE $mt SET domain_id='$di' WHERE redir='$red'");
    ++$i;
    }
    ?>
    PM me if it works properly.
    regards :)
     
    JEET, Jul 25, 2007 IP