简体   繁体   中英

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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