php 遍历 更新 求教! 在线等、 本帖最后由 qqmnme 于 2011-11-10 18:45:30 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach( $arr_hang as $lie ){mysql_query("update `user_list` set ext1 = ext1 + 2500 where `username`='$lie'" );if( mysql_affected_rows >= 0 ) echo "更新成功:".$lie;else echo "ERROR:".mysql_error();} 纳闷的是你写的代码也没有看出有错误 这是全部代码、<?php$dbhost='localhost';//数据库IP$dbname = 'sex';//数据库名$dbuser = 'test';//数据库用户名$dbpassword = '123';//用户密码$conn = mysql_connect($dbhost,$dbuser,$dbpassword);mysql_select_db($dbname,$conn);mysql_query("set names gb2312");$content=fread(fopen("pay5.txt",'r+'),filesize("pay5.txt"))."";$arr_hang=explode("\n",$content);foreach( $arr_hang as $lie ){mysql_query("update `user_list` set ext1 = ext1 + 2500 where `username`='$lie'" );if( mysql_affected_rows >= 0 ) echo "更新成功:".$lie;else echo "ERROR:".mysql_error();} $of = fopen("pay5.txt",'w+');//创建并打开wmlif($of){ fwrite($of,$s);//把执行文件的结果写入txt文件}?> 我写错了一点 mysql_affected_rows() 是个方法 你把 $arr_hang 打印出来,和数据库中的数据比对一下就知道为啥了 <?php$dbhost='localhost';//数据库IP$dbname = 'sex';//数据库名$dbuser = 'test';//数据库用户名$dbpassword = '123';//用户密码$conn = mysql_connect($dbhost,$dbuser,$dbpassword);mysql_select_db($dbname,$conn);mysql_query("set names gb2312");// 读取文件$readfile = fopen("pay5.txt",'r+');$content=fread(fopen("pay5.txt",'r+'),filesize("pay5.txt"))."";fclose( $readfile);// 分行$arr_hang=explode("\n",$content);print_r( $arr_hang);echo "<br/>";foreach( $arr_hang as $lie ){mysql_query("update `user_list` set ext1 = ext1 + 2500 where `username`='$lie'" );if( mysql_affected_rows() >= 0 ) echo "更新成功:".$lie;else echo "ERROR:".mysql_error();} // 写入$of = fopen("pay5.txt",'w+');//创建并打开wmlif($of){ fwrite($of,$s);//把执行文件的结果写入txt文件 $s未定义吧!}?>每次更新不管有没有成功都会打印出信息的现在想想也许有乱码的可能。 伪静态问题 怎么让php生成唯一数字ID的重复度降低? php如何获取当前页面隐藏按钮value 最近整了个WINXP+IIS5.1+PHP+MYSQL,在PHPMYADMIN里遇到点问题,一直解决不了,望解…… 求高手解答!怎么才可以长期的引用音乐网的音乐地址,而不担心防盗链的限制! 请教:我在php中写的这个正则表达式怎么都不对,麻烦大哥帮忙看一下,谢谢了。 从数据库读出来的unicode在网页中无法正常显示 Apache2.0+PHPPHP-4.3.4-win32配置问题 PHP如何接收表单的数据 怎样控制上传图片的大小?高手请帮忙! 在XP中如何下载安装php编译器 求解?
mysql_query("update `user_list` set ext1 = ext1 + 2500 where `username`='$lie'" );
if( mysql_affected_rows >= 0 )
echo "更新成功:".$lie;
else
echo "ERROR:".mysql_error();
}
纳闷的是你写的代码也没有看出有错误
<?php
$dbhost='localhost';//数据库IP
$dbname = 'sex';//数据库名
$dbuser = 'test';//数据库用户名
$dbpassword = '123';//用户密码
$conn = mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbname,$conn);
mysql_query("set names gb2312");$content=fread(fopen("pay5.txt",'r+'),filesize("pay5.txt"))."";
$arr_hang=explode("\n",$content);foreach( $arr_hang as $lie ){
mysql_query("update `user_list` set ext1 = ext1 + 2500 where `username`='$lie'" );
if( mysql_affected_rows >= 0 )
echo "更新成功:".$lie;
else
echo "ERROR:".mysql_error();
}
$of = fopen("pay5.txt",'w+');//创建并打开wml
if($of){
fwrite($of,$s);//把执行文件的结果写入txt文件
}?>
你把 $arr_hang 打印出来,和数据库中的数据比对一下就知道为啥了
<?php
$dbhost='localhost';//数据库IP
$dbname = 'sex';//数据库名
$dbuser = 'test';//数据库用户名
$dbpassword = '123';//用户密码
$conn = mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbname,$conn);
mysql_query("set names gb2312");
// 读取文件
$readfile = fopen("pay5.txt",'r+');
$content=fread(fopen("pay5.txt",'r+'),filesize("pay5.txt"))."";
fclose( $readfile);
// 分行
$arr_hang=explode("\n",$content);print_r( $arr_hang);
echo "<br/>";foreach( $arr_hang as $lie ){
mysql_query("update `user_list` set ext1 = ext1 + 2500 where `username`='$lie'" );
if( mysql_affected_rows() >= 0 )
echo "更新成功:".$lie;
else
echo "ERROR:".mysql_error();
} // 写入
$of = fopen("pay5.txt",'w+');//创建并打开wml
if($of){
fwrite($of,$s);//把执行文件的结果写入txt文件 $s未定义吧!
}
?>每次更新不管有没有成功都会打印出信息的
现在想想也许有乱码的可能。