<? if column is empty insert this content ?> How ?

Discussion in 'PHP' started by earngate, May 13, 2010.

  1. #1
    Hello,
    we have web directory script have 50000 links and some links haven't its keywords

    1- this is links table structure
    
    
    CREATE TABLE IF NOT EXISTS `dn_links` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `url` varchar(255) NOT NULL default '',
      `recip` varchar(255) NOT NULL default '',
      `title` varchar(255) NOT NULL default '',
      `description` varchar(255) NOT NULL default '',
      `detail` text NOT NULL,
      `keywords` text NOT NULL,
    )  ;
    
    
    Code (markup):
    2-we have function to get meta

    
    function link_submitted_meta($in) {
    global $s,$m;
    $form = get_meta_tags($in[url]);
    $form[url] = $in[url];
    if (!$form[title])
    { $x = file($in[url]);
      foreach ($x as $k=>$v)
      { $k = strstr(trim(stripslashes($v)),'<TITLE>'); if (!$k) $k = strstr(trim(stripslashes($v)),'<title>');
        if ($k) { $form[title] = eregi_replace('<title>','',eregi_replace('</title>','',$k)); break; } 
      }
    }
    $s[subm_all] = 1;
    link_submit_form($in[selected_category],$form);
    }
    
    
    PHP:
    so that we want
    php code to check if " keyword filed is empty " > generate keyword automatically by this function
    and insert keywords to this field
    How we do that ?
     
    earngate, May 13, 2010 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just run a mysql query to see if the keyword field doesn't have any data, i.e.:

    
    $query = "SELECT * FROM dn_links WHERE keywords = \"\"";
    $result = mysql_query($query);
    while($link = mysql_fetch_object($result)) {
    	// run you function here for each link
    }
    
    PHP:


    That will return all the links in your table that don't have a keyword set.
     
    Christian Little, May 13, 2010 IP
  3. earngate

    earngate Well-Known Member

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    thanks for code but please explain more
    because we tried this

    
    <?
    
    include('connect.php');
    
    $query = "SELECT * FROM dn_links WHERE keywords = \"\"";
    $result = mysql_query($query);
    while($link = mysql_fetch_object($result)) {
    function link_submitted_meta($in) {
    global $s,$m;
    $form = get_meta_tags($in[url]);
    $form[url] = $in[url];
    if (!$form[title])
    { $x = file($in[url]);
      foreach ($x as $k=>$v)
      { $k = strstr(trim(stripslashes($v)),'<TITLE>'); if (!$k) $k = strstr(trim(stripslashes($v)),'<title>');
        if ($k) { $form[title] = eregi_replace('<title>','',eregi_replace('</title>','',$k)); break; } 
      }
    }
    $s[subm_all] = 1;
    link_submit_form($in[selected_category],$form);
    }
    
    
    }
    
    
    ?>
    
    
    
    Code (markup):
    But we found this error

    Fatal error: Cannot redeclare link_submitted_meta() (previously declared in /home/public_html/digint/demo.php:8) in home/public_html/digint/demo.php on line 8

    Please add to us code that help us to do this

    <? if keyword filed is empty get_meta_tags($in) insert it to database ?>[/B]
     
    earngate, May 13, 2010 IP
  4. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Fatal error: Cannot redeclare link_submitted_meta() (previously declared in /home/public_html/digint/demo.php:8) in home/public_html/digint/demo.php on line 8
    PHP:
    That error is caused by declaring the function link_submitted_meta() twice. In that code above you have:

    function link_submitted_meta($in) {
    PHP:
    However, according to PHP you are running a script called demo.php which also declares that function.
     
    Christian Little, May 14, 2010 IP
  5. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #5
    you may have re-included that file again, try include_once or do something in your function like:
     
    gapz101, May 14, 2010 IP
  6. earngate

    earngate Well-Known Member

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    we used this code

    
    
    $result = mysql_query("SELECT id,url,keywords FROM dn_links") or die(mysql_error());if(mysql_num_rows($result) >= 1){    while($item = mysql_fetch_object($result)){        if(empty($item->keywords)){            $tags = get_meta_tags($item->url);            mysql_query("UPDATE dn_links SET keywords='" . $tags['keywords'] . "' WHERE id=" . $item->id) or die(mysql_error());        }    }} 
    
    
    PHP:
    it's done
    A-data inserted like this ???? ????????? ? ????????
    database Collation latin1_swedish_ci

    B-because our web directory have 30000 links
    1-this operation take too much time and we get " Fatal error: Maximum execution time of 30 second exceeded "



    there is any fix to this ?
     
    earngate, May 14, 2010 IP
  7. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #7
    A -> set names utf8
    B -> set timeout to zero(0) or do it by batch
     
    gapz101, May 15, 2010 IP
  8. live.co.uk

    live.co.uk Banned

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    use if !empty
     
    live.co.uk, May 15, 2010 IP
  9. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #9
    why ! ? it's checking if it is empty then assign autogenerate keyword
     
    gapz101, May 15, 2010 IP