21,890
社区成员
发帖
与我相关
我的任务
分享category | tag1 | tag2 | tag3 | tag4 | tag5
art | paint | picture| sculpture | photo | bronze
tourism | tourism | travel | tour | journey | trip
fashion | style | vogue | fashion | mode | Popular
... <?php
header('Content-type:text/html; charset=utf-8');
$db = mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT content,id,directory,date FROM articles WHERE Order By date DESC");//从文章数据库里获得所有的文章。
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
$content = $row['content'];
$words = preg_split("/\s+/",$content);
$uniqueWords = array_keys(array_flip($words)); //将没条文章分割成一个一个单词
$parts = '';
foreach($uniqueWords as $word){
$parts[] = " tag1 = '$word' OR tag2 = '$word' OR tag3 = '$word' OR tag4 = '$word' OR tag5 = '$word' ";
}
$where = implode(" OR ", $parts);
mysql_select_db("mydb",$db);
mysql_query("SET NAMES utf8");
$query = mysql_query("SELECT * FROM tags1 WHERE ($where) AND category='art' "); // 把上面分割的单词放进TAG1表中,进行检索,如果文章中有文字和tag1表列中相吻合,输出category='art',如果没有,跳过不输出。
$citn = '';
while ($row = mysql_fetch_array($query)) {
$citn = $row['category'];
}
$catnew = $citn;
mysql_query("UPDATE articles SET directory = '".$catnew."' WHERE id = '".$id."' AND directory ='0' Order By date DESC LIMIT 5"); // 根据ID号匹配,UPDATE文章数据表,这里我试验时用了60篇文章,但是输完后查询数据库,却有11条文章的directory升级成了 'art'
}
mysql_close($db);
?>
// 晕了,这里重复使用$count变量,导致运行不成功, 这样改
// 不建议用while, 仅仅是返回是否有还是没有
$_count = 0;
while ($row = mysql_fetch_array($query)) {
$_count = $row['count'];
}
// 说明找到了分类
if($_count) {
//记录分类, 这里还可以验证directory是否 ='0'才记录分类
$ids[] = $row['id'];
$count++;
// 高潮部分
if($count == 5) {
// 进行更新
mysql_query("UPDATE articles SET directory = '".$curCategory."' WHERE id in ('".implode("', '", $ids)."')");
// 获取下一个分类
if(!$curCategory = array_shift($categories)) {
// 没有分类结束
break;
}
// 重新计数
$count = 0;
// 记录更新文章的id
$ids = array();
}
}
$query = mysql_query("SELECT count(*) as count FROM tags1 WHERE ($where) AND category='$curCategory' ");
"SELECT count(*) as count FROM tags1 WHERE ($where) AND category='$curCategory' "$query = mysql_query("SELECT count(*) as count FROM tags1 WHERE ($where) AND category='$curCategory' ");while ($row = mysql_fetch_array($query)) {
$count = $row['count'];
echo $count;//输出 00100000111000011000000000000010000000000100010110001000000
}
<?php
header('Content-type:text/html; charset=utf-8');
$db = mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT content,id,directory,date FROM articles WHERE Order By date DESC");//从文章数据库里获得所有的文章。
// 统计一个分类中的最大文章个数
$count = 0;
// 记录更新文章的id
$ids = array();
// 分类的总数量
$categories = array('art', 'tourism', 'fashion');
// 当前分类
$curCategory = array_shift($categories);
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
$content = $row['content'];
$words = preg_split("/\s+/",$content);
$uniqueWords = array_keys(array_flip($words)); //将没条文章分割成一个一个单词
$parts = '';
foreach($uniqueWords as $word){
$parts[] = " tag1 = '$word' OR tag2 = '$word' OR tag3 = '$word' OR tag4 = '$word' OR tag5 = '$word' ";
}
$where = implode(" OR ", $parts);
mysql_select_db("mydb",$db);
mysql_query("SET NAMES utf8");
// 仅仅验证的话,就count吧
$query = mysql_query("SELECT count(*) as count FROM tags1 WHERE ($where) AND category='$curCategory' "); // 把上面分割的单词放进TAG1表中,进行检索,如果文章中有文字和tag1表列中相吻合,输出category='art',如果没有,跳过不输出。
// 不建议用while, 仅仅是返回是否有还是没有
$count = 0;
while ($row = mysql_fetch_array($query)) {
$count = $row['count'];
}
// 说明找到了分类
if($count) {
//记录分类
$ids[] = $row['id'];
$count++;
// 高潮部分
if($count == 5) {
// 进行更新
mysql_query("UPDATE articles SET directory = '".$curCategory."' WHERE id in ('".implode("', '", $ids)."')");
// 获取下一个分类
if(!$curCategory = array_shift($categories)) {
// 没有分类结束
break;
}
// 重新计数
$count = 0;
// 记录更新文章的id
$ids = array();
}
}
// 这两句不要了
//$catnew = $citn;
//mysql_query("UPDATE articles SET directory = '".$catnew."' WHERE id = '".$id."' AND directory ='0' Order By date DESC LIMIT 5"); // 根据ID号匹配,UPDATE文章数据表,这里我试验时用了60篇文章,但是输完后查询数据库,却有11条文章的directory升级成了 'art'
}
mysql_close($db);
?>
<?php
header('Content-type:text/html; charset=utf-8');
$db = mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT content,id,directory,date FROM articles WHERE Order By date DESC");//从文章数据库里获得所有的文章。
// 统计一个分类中的最大文章个数
$count = 0;
// 记录更新文章的id
$ids = array();
// 分类的总数量
$categories = array('art', 'tourism', 'fashion');
// 当前分类
$curCategory = array_shift($categories);
while ($row = mysql_fetch_array($result))
{
$id = $row['id'];
$content = $row['content'];
$words = preg_split("/\s+/",$content);
$uniqueWords = array_keys(array_flip($words)); //将没条文章分割成一个一个单词
$parts = '';
foreach($uniqueWords as $word){
$parts[] = " tag1 = '$word' OR tag2 = '$word' OR tag3 = '$word' OR tag4 = '$word' OR tag5 = '$word' ";
}
$where = implode(" OR ", $parts);
mysql_select_db("mydb",$db);
mysql_query("SET NAMES utf8");
// 仅仅验证的话,就count吧
$query = mysql_query("SELECT count(*) as count FROM tags1 WHERE ($where) AND category='$curCategory' "); // 把上面分割的单词放进TAG1表中,进行检索,如果文章中有文字和tag1表列中相吻合,输出category='art',如果没有,跳过不输出。
// 不建议用while, 仅仅是返回是否有还是没有
$count = 0;
while ($row = mysql_fetch_array($query)) {
$count = $row['count'];
}
// 说明找到了分类
if($count) {
//记录分类
$ids[] = $row['id'];
$count++;
// 高潮部分
if($count == 5) {
// 进行更新
mysql_query("UPDATE articles SET directory = '".$curCategory."' WHERE id in ('".implode("', '", $ids)."')");
// 获取下一个分类
if(!$curCategory = array_shift($categories)) {
// 没有分类结束
break;
}
// 重新计数
$count = 0;
// 记录更新文章的id
$ids = array();
}
}
$catnew = $citn;
mysql_query("UPDATE articles SET directory = '".$catnew."' WHERE id = '".$id."' AND directory ='0' Order By date DESC LIMIT 5"); // 根据ID号匹配,UPDATE文章数据表,这里我试验时用了60篇文章,但是输完后查询数据库,却有11条文章的directory升级成了 'art'
}
mysql_close($db);
?>