当我使用 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() 是否在 while 循环内不起作用??
最佳答案
在函数的列传递上提供ALIAS
。
$select="SELECT LEFT(description,500) description FROM tbl_news where id='$id'";
作为旁注,该查询容易受到 SQL Injection
的影响。如果变量的值(s)来自外部。请查看下面的文章,了解如何预防这种情况。通过使用 PreparedStatements
,您可以摆脱在值周围使用单引号的情况。
关于php - Left() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14600509/