简体   繁体   English

我如何输出具有ID的行,让我们说31

[英]How can I output a row with id lets say 31

<?php
$link = mysql_connect('localhost', 'username', 'password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

if (!mysql_select_db('database'))
    die("Can't select database");


// choose id 31 from table users

echo $id; //31
echo $name; //id31's name
echo $surname //id31's surname
echo $blablabla //id31's blablabla

mysql_close($link);
?>

Give this a shot: 试一下:

$id = mysql_real_escape_string(31);
$result = mysql_query('SELECT * FROM `users` where `id` = ' . $id . ' LIMIT 1');

$row = mysql_fetch_assoc($result);

echo $row['id']; // 31
echo $row['name']; // name
// etc..

// If you wanted to output ALL the fields you could loop through
foreach($row as $field_name => $value) {
  echo $field_name . ': ' . $value . '<br />';
}

// The output would look something like
// id: 31
// name: John Smith
// ...

Functions Used: 使用的功能:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM