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未定义吧!}?>每次更新不管有没有成功都会打印出信息的现在想想也许有乱码的可能。 同一个页面不同的DIV,如何分页? 看了这个面试题我直接说 我不会php HTTP 错误 401.3 - 未经授权:访问由于 ACL 对所请求资源的设置被拒绝 js调用参数 求教两个Apache的问题,急~有经验的大大进! php5出现:using $this when not in object 一个小问题?谢谢 还是表单传递变量的问题……(又是老问题,烦死了:p) centOS yum安装好php后测试不成功 大神帮我看看,为什么我的PHP页面接收不到AJAX传递来的值 在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未定义吧!
}
?>每次更新不管有没有成功都会打印出信息的
现在想想也许有乱码的可能。