0

I perform the mysql query to check if any number of row effected on the user input data with the help of mysql_num_rows($query). Only one row will effect always as I made some rows are unique. If one row effect, I want to get the ID of that Row. I means the auto increment ID of the same row.

The same row contains many fields, its better if I come to know how to get the entry of other fields.

Thanks stack for your solutions.

4

3 回答 3

1

你试过SELECT id FROM table WHERE value=condition吗?如果您查询,您将获得与您的条件匹配的行的 id。将 id 替换为标识符行,将 table 替换为您的表名,将 value 和 condition 替换为您的条件。

$query = "SELECT id FROM table WHERE value=condition";
$result = mysql_query($query);
if ($row = mysql_fetch_row($result)) {
  //$row contains valid information.
}

顺便说一句:不要再使用 mysql_*,它已被弃用,请查看 PDO 或 mysqli_*

于 2013-07-04T16:10:39.580 回答
0
$query = "SELECT mysql_id
          FROM table";
$stmt = $db->prepare($query);
$stmt->execute();
$id = $stmt->fetchColumn();

您可能必须在查询语句中添加“WHERE”子句,然后使用准备好的语句将值传递到数组中。

于 2013-07-04T16:13:06.667 回答
0

只需mysql_insert_id(); 在执行插入查询后使用此功能。

 $query = "INSERT INTO test (value) VALUES ('test')";
 mysql_query( $query );
 $lastInsertId=mysql_insert_id();
 echo $lastInsertId;
于 2013-07-04T16:13:21.073 回答