Anoop
Anoop

Reputation: 242

Left() not working

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??

Upvotes: 2

Views: 111

Answers (1)

John Woo
John Woo

Reputation: 263733

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.

Upvotes: 3

Related Questions