$q=substr($q,0,(strlen($q)-3));
Above code will remove last 3 chars from the string $q. SELECT * FROM `table_name` WHERE student_id IN ( 1,2,3,4)
To our original query we may add variable part like this
$query1="SELECT * FROM table_name WHERE student_id ";
$query2= " IN ( 1,2,3,4) ";
$query=$query1.$query2;
To generate this query we may have to loop through a for loop or any other loop and generate the variable part of the query string with one extra coma ( , ) at the end . $query=substr($query,0,(strlen($query)-1));
This is in use for our search query generation string tutorial
strlen to know the length of the string
substr to remove part of the string