当我使用LEFT()使用以下代码从数据库中获取值时
$select="SELECT LEFT(description,500) FROM tbl_news where id='$id'";
$quer=mysqli_query($select);
$fetch=mysqli_fetch_array($quer);
$descr=$fetch['description'];
echo $descr;
该值没有回显...... LEFT()是否在循环中无效?
答案 0 :(得分:3)
在函数的列传递上提供ALIAS
。
$select="SELECT LEFT(description,500) description FROM tbl_news where id='$id'";
作为旁注,如果变量的值( s )来自外部,则查询易受SQL Injection
攻击。请查看下面的文章,了解如何防止它。通过使用PreparedStatements
,您可以摆脱在值周围使用单引号。