2

When i used the LEFT() to fetch the values from database using the following code

$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;

The value is not echoing... Is the LEFT() didn't work inside while loop??

4

1 に答える 1

3

supply an ALIAS on the column pass on the function.

$select="SELECT LEFT(description,500) description FROM tbl_news where id='$id'";

As a sidenote, the query is vulnerable with SQL Injection if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements you can get rid of using single quotes around values.

于 2013-01-30T09:28:03.430 に答える