In PHP, we will be requiring to remove the last Character from a string variable.
For example, consider below query.
select * from employees where employee_id in (1,2,5,7)
Assume that the employee_id values 1,2,5,7 should be dynamically collected from a webpage provided with checkboxes to select some employees from a list of employees.
Using foreach loop we can create this employee_id string. But it will look like as below
$employee_id_string="1,2,5,7,";
You can note the last comma.
Error will be thrown if we use this as it is
select * from employees where employee_id in ($employee_id_string)
In this case we need to remove this last comma.
It can be easily done by below code.
$employee_id_string=substr($employee_id_string,0,-1);
More Articles...
Tuesday, December 8, 2009
Search This Blog
Blog Archive
-
▼
2009
(257)
-
▼
December
(13)
- Released javascript widget for showing New Year Qu...
- Released eBooks for learning Software Testing and QTP
- Added more questions in our online Quiz
- News Letter
- Released Free widget for showing Christmas Quotes
- Use associative array instead of using querystring...
- Clearing Cache in phpBB forum
- Boost your adSense revenue by using Category filter.
- New blog from QualityPoint for showing latest News...
- Parsing webpage using php DOM.
- Setting UserAgent for php curl session to avoid 50...
- Latest Articles for learning Web Development usin...
- Removing Last Character in a String
-
▼
December
(13)

AI Course | Bundle Offer | Unlocking AI | Dream Big | Listen to Dream Big
Today's Deals | Timesheet | Products | SQL ebook | Earn 50% commission
About | Privacy | Follow | TOS | WhatsApp | Contact
I may earn a commission from Amazon affiliate links
1 comment:
Well my friend, you should add '0' at the end of the string, because some time you will come across that the IN string is empty and mysql will trhough error on that, therefore zero will save you as ids are always greater then 0.
Thanks,
Najm.
Post a Comment