如何通过查询同一行中的另一个值来返回特定mysql单元中的whats?

| 我正在尝试制作一个php页面,我可以将其导航至... http://mydomain.com?id=12345 在我的mysql表中有一个id列和一个text列....如何使我的php页面获取ID,找到它,然后在同一行的文本单元格中返回内容并在页面上回显它? 到目前为止,这是我想出的办法。.我大部分时间都停留在我应该使用Mysql查询做的事情上。然后如何实际将数据转换成我可以回显到页面的变量。谢谢! 编辑:取得了一些进展...
    <?php 

    mysql_connect(\"my.mysql.com\", \"user\", \"pass\");
    mysql_select_db(\"mydb\");

    $id= $_GET[\'id\'];

   $result = mysql_query(\"SELECT text FROM mytable WHERE id=\'$id\'\")
or die(mysql_error());  


echo nl2br($result);


    ?>
    
已邀请:
构造查询后,立即将其传递到数据库并获取结果
// Perform Query
$result = mysql_query($query);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = \'Invalid query: \' . mysql_error() . \"\\n\";
    $message .= \'Whole query: \' . $query;
    die($message);
}

// Use result
// Attempting to print $result won\'t allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($result)) {
    echo $row[\'field1\'];
    echo $row[\'field2\'];
}

// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);
重要说明:在将数据输入数据库之前,应始终对数据进行清理,以避免sql注入 例如:假设有人在URL中将\“ \'; drop table mytable; \”作为ID。然后将此传递给mysql将删除您的表。 注意2:输出文章时,请确保转义某些字符:您应输入&lt和​​&gt而不是<和> 推荐教程 脚本从这里复制     
SELECT
之后指定要提取的字段
SELECT field1, field2
  FROM mytable
  WHERE id=:id
    

要回复问题请先登录注册