时间:2021-07-01 10:21:17 帮助过:43人阅读
//拆分发来的信息得到会员卡号 $arry=explode("+",$form_Content); $memberid =$arry[1]; //连接数据库 $link=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); if($link) { mysql_select_db(SAE_MYSQL_DB,$link); //查询数据 $result1=mysql_query("select * from numbers where pmcode = '".$memberid."';"); $num_result = mysql_num_rows($result1); if($num_result==1){ // $row= $result1->fetch_assoc(); $row=mysql_fetch_row($result1); $result_str="您的会员--信息如下:\n\n卡号:$row[pmcode].\n姓名:.$row[names].\n等级:.$row[4].\n积分:$a[5]"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,$result_str); echo $resultStr; exit; }else{ $msgType = "text"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,"--select * from numbers where pmcode = '".$memberid."'"); echo $resultStr; exit; } } else{ echo "连接数据库失败".mysql_error; } mysql_close($link); }
if($num_result==0){ // $row= $result1->fetch_assoc(); $row=mysql_fetch_row($result1); $result_str="您的会员--信息如下:\n\n卡号:$row[pmcode].\n姓名:.$row[names].\n等级:.$row[names].\n积分:$a[names]"; $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType,$result_str); echo $resultStr; exit;
echo $memberid; 得到什么值,把sql复制到dos命令行下执行能得到数据吗
echo $memberid; 得到什么值,把sql复制到dos命令行下执行能得到数据吗
得到的是正确的值。
$num_result = mysql_num_rows($result1);
echo $num_result; //输出什么
$num_result = mysql_num_rows($result1);
echo $num_result; //输出什么
1
那不就对了,你主帖的代码没问题,应该可以进入if里面。
那不就对了,你主帖的代码没问题,应该可以进入if里面。
取出一条数据后,怎么获得里面的属性,怎么把pmcode,names之类的打印出来?
$row=mysql_fetch_row($result1);
print_r($row);
$row=mysql_fetch_row($result1);
print_r($row);
只取names这个属性呢?
$row['names']
$row['names']
$link=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); if($link) { mysql_select_db(SAE_MYSQL_DB,$link); $memberid="J00000000B005"; //查询数据 $result1=mysql_query("select * from numbers where pmcode = '".$memberid."'"); $row=mysql_fetch_row($result1); $num_result = mysql_num_rows($result1); if($num_result==1){ $resultStr= $row['names']; echo "fff".$resultStr; exit; }else{ echo "未找到数据"; } } else{ echo "连接数据库失败".mysql_error; } mysql_close($link);
print_r($row); // 贴出结果
Array ( [0] => J00000000B005 [1] => ?ㄧ??? [2] => F [3] => [4] => [5] => 20121012 [6] => 20130430 [7] => Z [8] => JE11 [9] => 0 [10] => 0 [11] => 0 [12] => [13] => )
print_r($row); // 贴出结果
Array ( [0] => J00000000B005 [1] => ?ㄧ??? [2] => F [3] => [4] => [5] => 20121012 [6] => 20130430 [7] => Z [8] => JE11 [9] => 0 [10] => 0 [11] => 0 [12] => [13] => )
哦,我搞错了。
echo $row[1];
有乱码,query前面加上一句:mysql_query("set names utf8"); 试试
你把mysql_fetch_row改成mysql_fetch_assoc试下。。。然后打印数组