这有效
<?php
$result = $conn->query('SELECT * FROM people
WHERE user="55"') or die(mysql_error());
$row = mysqli_fetch_array( $result );
echo $row['name'];
?>
但是当我尝试使用php变量时,以下内容不起作用:
<?php
$a = 55;
$result = $conn->query('SELECT * FROM people
WHERE user="$a"') or die(mysql_error());
$row = mysqli_fetch_array( $result );
echo $row['name'];
?>
答案 0 :(得分:2)
试试这个:
$query = 'SELECT * FROM people WHERE user="'.$a.'"';
答案 1 :(得分:0)
您必须连接如下所示的值
<?php $result = $conn->query('SELECT * FROM people WHERE user="'.$a.'"') or die(mysql_error());
$row = mysqli_fetch_array( $result );
echo $row['name']; ?>
答案 2 :(得分:0)
更改此内容: $ result = $ conn-&gt; query(&#39; SELECT * FROM people WHERE user =&#34; $ a&#34;&#39;)或die(mysql_error());
至此: $ result = $ conn-&gt; query(&#34; SELECT * FROM people WHERE user =&#39; $ a&#39;&#34;)或die(mysql_error());