请人帮忙看下这段php代码,找不出错哪了

WBOY
Release: 2016-06-13 10:13:06
Original
917 people have browsed it

请人帮忙看下这段php代码,找不出哪里错了
mysql_connect("localhost", "root", "") or
  die("Could not connect: " . mysql_error());
  mysql_select_db("sdedecmsv57utf8sp1");
  $result = mysql_query("SELECT title FROM dede_archives");  
  $file_index=1;
  $i=1;
  while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  !$i%20 ? $file_index++ : $i++; 
  file_put_contents ( $file_index.'txt' , $row[0], FILE_APPEND );  
  }
  mysql_free_result($result);
?>

------解决方案--------------------

!$i%20 ? $file_index++ : $i++; 
換成
if($i%20==0){
$file_index++;
}
$i++;
因為無論是否產生新的$file_index,$i都需要增長 
你看下是不是你想要的結果
------解决方案--------------------
这一般是sql语句有问题,你把sql语句放在phpadmin里或mysql命令行里执行一下看是否正确选出结果。应该就是语句的错误
------解决方案--------------------
mysql_select_db("sdedecmsv57utf8sp1");

dede安装默认数据库是dedecmsv57utf8sp1,你前面好像多加了个 's'
要去掉还不行的话 只可能是数据库连接错误了
------解决方案--------------------
那个问号我记得写的是中文的
------解决方案--------------------

探讨

引用:

No database selected

没有选择数据库。你仔细检查哪部分写错 了。

嗯嗯,是数据库名我粗心多加了个s
再请教下保存成一个标题一行的该怎么写?
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!