日期:2014-05-17  浏览次数:20412 次

php如何取的指定id的值啊
php如何取的指定id的值啊 
如:
$sql="select * from customers where customers_id=".$_GET["id"];
$result=mysql_query($sql,$conn) or
die("error:".mysql_error);

$num=mysql_num_rows($result);
if ($num >0) {
 ....这里如何写啊 ,如果有相同的值 是不是就出来两个啊 我只要第一个

}
?>

------解决方案--------------------
PHP code

if($num>0){

$row = mysql_fetch_assoc($result);
 print_r($row);

}

------解决方案--------------------
PHP code

$sql="select * from customers where customers_id=".$_GET["id"];
$result=mysql_query($sql,$conn) or
die("error:".mysql_error);

$num=mysql_num_rows($result);
if ($num >0) {
mysql_fetch_array($result); 

}
?>

------解决方案--------------------
$result=mysql_query($sql,$conn)
你得到结果集??
你是想从多个行中取第一个行吧??
$rows=mysql_fetch_row($result)
这就是一行了,如果有多行,默认为第一行!
------解决方案--------------------
总感觉你这么写SQL语句有问题
------解决方案--------------------
探讨
php如何取的指定id的值啊
如:
$sql="select * from customers where customers_id=".$_GET["id"];
$result=mysql_query($sql,$conn) or
die("error:".mysql_error);

$num=mysql_num_rows($result);
if ($num >0) {
....这里如何写啊 ,如果有相同的值 是不是就出来两个啊 我只要第一个

}
?>


------解决方案--------------------
id 如果是自动生成的就不会有重复的吧