查询未使用动态值执行

时间:2013-01-07 12:01:37

标签: php mysql excel variables select

我正在$number_column变量

中的excel表中读取值
$number_column = $data->sheets[0]['cells'][$row1][1];

然后进行选择查询

$query_patent = "SELECT `id` FROM `ipoverview` WHERE number ='$number_column'";

它不起作用。如果我回复了我的$number_column我正在该位置获取数据。

如果将任何数字硬编码到$number_column,则该查询正在执行。

 $number_column="12345";
 echo $query_patent = "SELECT `id` FROM `ipoverview` WHERE number ='$number_column'"; //This works

帮我解决这个问题??

3 个答案:

答案 0 :(得分:1)

确保将UTF-8作为excel文件的字符编码, 并确保您应该将utf8_general_ci作为数据库列的排序规则 有关详细信息,请参阅http://docs.php.net/manual/en/mysqli.set-charset.php。 感谢

答案 1 :(得分:0)

试试这个。还有echo $query_patent是否在执行查询之前获得该变量的变量..

echo $query_patent = "SELECT `id` FROM `ipoverview` WHERE number ='".$number_column."'";

上述回声的响应

SELECT `id` FROM `ipoverview` WHERE number = 'E1234A'    
SELECT `id` FROM `ipoverview` WHERE number = 'E1234B'
SELECT `id` FROM `ipoverview` WHERE number = 'E1234C'

答案 2 :(得分:0)

你有这条线:

echo $query_patent = "SELECT `id` FROM `ipoverview` WHERE number ='$number_column'";

不应该是这样的:

$query_patent = "SELECT `id` FROM `ipoverview` WHERE number ='$number_column'";
$rResult = mysqli_query($dblink,$query_patent)or die("something went wrong when executing this query:<br /><br />" + $query_patent + "<br /><br />"+ mysqli_error($dbLink));
// Dot Stuff with $rResult
while($row = mysqli_fetch_row($rResult)){
    print_r($row);
}