简体   繁体   English

使用mysql_query进行变量声明

[英]Use of mysql_query for variable declaration

In the following PHP code, s_at is a column that includes integer values in database. 在以下PHP代码中, s_at是一个包含数据库中的整数值的列。 I need to declare one of that value where index is 1, to $s_at . 我需要将index为1的值声明为$s_at But won't happen in this way. 但不会以这种方式发生。 I'm glad if anyone could help. 如果有人能提供帮助,我很高兴。

$s_at  = mysql_query("Select('s_at') FROM `time_holder` WHERE `index` = 1");

quite easy: 很简单:

$mi_resource = mysql_query("Select `s_at` FROM `time_holder` WHERE `index` = 1");
// .... error checking left out

$records = mysql_fetch_assoc($mi_resource);
// .... error checking left out

$s_at = $records[$record_num]['s_at']; // probably #0 if only one record.

...

see mysql_query mysql_query

Change your code to this and it will work for sure : 将您的代码更改为此,它肯定会起作用:

$result = mysql_query("Select `s_at` FROM `time_holder` WHERE `index` = 1");
$row = mysql_fetch_array($result);
$s_at = $row['s_at'];

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

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