Heim  >  Artikel  >  Backend-Entwicklung  >  php怎么取的指定id的值

php怎么取的指定id的值

WBOY
WBOYOriginal
2016-06-13 13:50:251127Durchsuche

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);

}
<br><font color="#e78608">------解决方案--------------------</font><br>
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); 

}
?>
<br><font color="#e78608">------解决方案--------------------</font><br>$result=mysql_query($sql,$conn)<br>你得到结果集??<br>你是想从多个行中取第一个行吧??<br>$rows=mysql_fetch_row($result)<br>这就是一行了,如果有多行,默认为第一行!
<br><font color="#e78608">------解决方案--------------------</font><br>总感觉你这么写SQL语句有问题
<br><font color="#e78608">------解决方案--------------------</font><br>
探讨
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 如果是自动生成的就不会有重复的吧
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn