Rishabh Anand Rishabh Anand - 1 year ago 80
MySQL Question

distinct selection from the session variables

line 21:-

$sql="SELECT DISTINCT sem from $_SESSION['ye']";

and I get an error

" Parse error: syntax error, unexpected ''
(T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or
variable (T_VARIABLE) or number (T_NUM_STRING) in
C:\xampp\htdocs\try1\Model\attendanceModel.php on line 21"

Answer Source

When interpolating array items into a string you need to use the complex interpolation syntax (wrap it in {}):

$sql = "SELECT DISTINCT `sem` from `{$_SESSION['ye']}`";

It is generally simpler to just save the value to an auxiliary variable. It can make your code easier to read:

$ye  = $_SESSION['ye'];
$sql = "SELECT DISTINCT `sem` from `$ye`";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download