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

we have web directory script have 30000 links and some links haven’t its keywords or details

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,

Please add to us code that help us to do this

<? if keyword filed is empty
get_meta_tags($in) and insert it to field
?>

i hope you understand us

Now we tried and we solve keyword importer
and now still one problem
if this code like this to get new links or articles in its template


{ $table = $s[item_types_tables][$what];
  $data[$what][new_items] = create_in_files_get_new_items($what);
  $q = dq("select * from $s[pr]cats where use_for = '$what' AND visible = '1' AND level = '1' order by name",1);

}

if ($mark=='new_items') 
                 { //foreach ($item_array as $k5=>$v5) echo "$k5 - $v5<br>";
            if ($what=='links') $new_items[$what][$st][] = php_rebuild_parse_part('new_links_template.html',$st,$item_array);
}


How get new links or article in category number #72 ??

Thanks rajug,
it’s work now but we have request please

1-we have spider that import links from google but its import url, title and description, we want it import also keywords

this is code



function spider_link($url,$title,$description,$keywords) {
global $s;
$s[x]++;
echo '<tr>
<td align="left" colspan="2"><span class="text13"><input class="bbb" type="checkbox" name="import_it[]" value="'.$s[x].'" checked> <a target="nove" href="'.$url.'">'.$title.'</a><br />'.$description.'<br /></td>
</tr>
<tr>
<td align="left"><span class="text13">URL: </td>
<td align="left"><input class="field10" name="url['.$s[x].']" style="width:550px" maxlength=255 value="'.$url.'"></td>
</tr>
<tr>
<td align="left"><span class="text13">Title: </td>
<td align="left"><input class="field10" name="title['.$s[x].']" style="width:550px" maxlength=255 value="'.$title.'"></td>
</tr>
<tr>
<td align="left"><span class="text13">Description: </td>
<td align="left"><input class="field10" name="description['.$s[x].']" style="width:550px" maxlength=255 value="'.replace_once_text($description).'"></td>
</tr>
<tr>
<td align="left"><span class="text13">Keywords: </td>
<td align="left"><input class="field10" name="keywords['.$s[x].']" style="width:550px" value="'.$keyword.'"></td>
</tr>';
}

we tried to use this


function spider_link($url,$title,$description,$keywords) {
global $s;
[COLOR="red"][B]$tags = get_meta_tags('.$url.');[/B][/COLOR]
$s[x]++;
echo '<tr>
<td align="left" colspan="2"><span class="text13"><input class="bbb" type="checkbox" name="import_it[]" value="'.$s[x].'" checked> <a target="nove" href="'.$url.'">'.$title.'</a><br />'.$description.'<br /></td>
</tr>
<tr>
<td align="left"><span class="text13">URL: </td>
<td align="left"><input class="field10" name="url['.$s[x].']" style="width:550px" maxlength=255 value="'.$url.'"></td>
</tr>
<tr>
<td align="left"><span class="text13">Title: </td>
<td align="left"><input class="field10" name="title['.$s[x].']" style="width:550px" maxlength=255 value="'.$title.'"></td>
</tr>
<tr>
<td align="left"><span class="text13">Description: </td>
<td align="left"><input class="field10" name="description['.$s[x].']" style="width:550px" maxlength=255 value="'.replace_once_text($description).'"></td>
</tr>
<tr>
<td align="left"><span class="text13">Keywords: </td>
<td align="left"><input class="field10" name="keywords['.$s[x].']" style="width:550px" value="'.[COLOR="red"][B]$tags[/B][/COLOR].'"></td>
</tr>';
}

to import keywords also but it’s faild

2-if this code like this to get new items in its template



{ $table = $s[item_types_tables][$what];
  $data[$what][new_items] = create_in_files_get_new_items($what);
  $q = dq("select * from $s[pr]cats where use_for = '$what' AND visible = '1' AND level = '1' order by name",1);

}

if ($mark=='new_items') 
                 { //foreach ($item_array as $k5=>$v5) echo "$k5 - $v5<br>";
            if ($what=='links') $new_items[$what][$st][] = php_rebuild_parse_part('new_links_template.html',$st,$item_array);
}

how get new item in category number #72 ??
we tried this but not work !!




{ $table = $s[item_types_tables][$what];
$data[$what][new_cat_items] = create_in_files_get_new_items($what);
$q = dq(“select * from $s[pr]cats where use_for = ‘$what’ AND visible = ‘1’ AND level = ‘1’ AND id=‘72’ order by name”,1);

}

if ($mark==‘new_catitems’)
{ //foreach ($item_array as $k5=>$v5) echo “$k5 - $v5<br>”;
if ($what==‘links’) $new
catitems[$what][$st][] = php_rebuild_parse_part('new_linkscat_72_template.html’,$st,$item_array);
}




can you help

Welcome to SP :slight_smile:
And no, I don’t understand you very well.
But it seems to me that you’d have to study a little bit. Try googling for ‘php mysql tutorial’, or read a bit around in the manuals:
http://www.php.net/manual/en/
http://dev.mysql.com/doc/refman/5.1/en/

I thinks would be enough:


$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());
        }
    }
}

Thanks guido2004,
My dear rajug
thanks for code and it work very good but we faced small problem,

A-data inserted like this ??? ??? ? ???
database cp1256_general_ci and sites charset is windows-1256

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

there is any fix to this ?

For A:
It seems you have some unicode characters in the table. Search in google for proper character set for your unicode characters.
For B:
This is obvious in such case. So better split the loop or use this script from cron job.