在MySQL和PHP中找到值的行的返回id
嘿,伙计们, 编写了一些代码,只是在MySQl中返回找到的值的行以及该行的列中的值时遇到了问题。 这就是我所拥有的在MySQL和PHP中找到值的行的返回id,php,mysql,search,return,row,Php,Mysql,Search,Return,Row,嘿,伙计们, 编写了一些代码,只是在MySQl中返回找到的值的行以及该行的列中的值时遇到了问题。 这就是我所拥有的 <?php //mysql deets $user="x"; $password="x"; $database="x"; $host="db285.x"; //open our db for check mysql_connect($host,$user,$password); @mysql_select_db($database) or die( "Unable to s
<?php
//mysql deets
$user="x";
$password="x";
$database="x";
$host="db285.x";
//open our db for check
mysql_connect($host,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$searchterm = "Dex";
$dbsearchterm = mysql_real_escape_string($searchterm);
$query = "SELECT * FROM contacts WHERE name='$dbsearchterm';";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
echo "found ".$searchterm."and the row it is in is ".$rownum." and value of the number column in row is ".$number;
}
else {
echo 'no find';
}
mysql_close();
?>
因此,我可以找到名称“dex”是否在其中,但如何在行的“number”列中返回并设置行id和值
谢谢各位,
Dex问题不是很清楚,但似乎您希望显示数据库中的值。如果是这样的话,那么这应该是可行的,如果这不是你想要的,请澄清你的问题
while ($row = mysql_fetch_assoc($res)) {
echo "found ".$searchterm."and the row it is in is ".$row['id']." and value of the number column in row is ".$row['number'];
}
您尚未发布数据库字段,因此请将键、
$row['id']
和$row['number']]
替换为数据库中的字段。问题不是很清楚,但您似乎想显示数据库中的值。如果是这样的话,那么这应该是可行的,如果这不是你想要的,请澄清你的问题
while ($row = mysql_fetch_assoc($res)) {
echo "found ".$searchterm."and the row it is in is ".$row['id']." and value of the number column in row is ".$row['number'];
}
您尚未发布数据库字段,因此请将键、
$row['id']
和$row['number']
替换为数据库中的字段。返回并设置?二者都设置为在assign a php variable中,或者设置为在update the MySql行中?设置为assign php var中,应该更清楚地说明这一点对不起!返回并设置?二者都设置为在assign a php variable中,或者设置为在update the MySql行中?设置为assign php var中,应该更清楚地说明这一点对不起!