<?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
答案 0 :(得分:1)
问题不是很清楚,但似乎您想要显示数据库中的值。如果是这样,那么这应该有效,如果这不是你想要的,请更好地澄清你的问题。
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']
。