表中提取一个值来创建一个新变量

表中提取一个值来创建一个新变量

本文介绍了通过从 MySQL 表中提取一个值来创建一个新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个页面,其中发布了一个变量 $submissionid.我想使用此变量并从名为 submission 的 MySQL 表中提取字段 subcheck.我希望 subcheck 字段的值只是一个新变量 $subcheck.我不知道该怎么做.我在下面有一个查询,但是如何将下面的查询结果转换为一个名为 $subcheck 的变量?(对于任何给定的提交 ID,将只有一个 $subcheck.)

I am using a page where a variable $submissionid is being posted to it. I would like to use this variable and pull the field subcheck from a MySQL table called submission. I would like the value of the field subcheck to simply be a new variable $subcheck. I'm not sure how to do this. I have a query below, but how to I convert the result of the query below into a variable called $subcheck? (For any given submissionid, there will only be one $subcheck.)

提前致谢,

约翰

$querysub = mysql_query("SELECT subcheck FROM submission WHERE submissionid = '$submissionid' ");
mysql_query($querysub) or die(mysql_error());

推荐答案

这应该有效:

$querysub = mysql_query("SELECT subcheck FROM submission WHERE submissionid = '" . $submissionid ."' ");
$result = mysql_query($querysub) or die(mysql_error());
$row = mysql_fetch_assoc( $result );
if ($row ) {
   $subcheck = $row['subcheck'];
} else {
    echo "Subcheck not found";
}

注意查询字符串中 $submissionid 周围的转义字符.在您的示例中,他们可能让变量的名称进入您发送到 mysql 服务器的字符串中.

Be careful with the escape characters around $submissionid in your query string. In your sample, they are probably letting the name of the variable go into the string you send to the mysql server.

这篇关于通过从 MySQL 表中提取一个值来创建一个新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:09