Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implode With Single Quotes

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
1
16
US
This little bit of code that I've been using for quite a while works fine for multiple numeric POSTS, which is what I generally have, but now I have some that are text. However, I can't seem to work out how to surround them with single quotes so that they will work in a query. Ideas?

Code:
if ($_POST['Segment3']) {
	if (count($_POST['Segment3']) > 0) {
		$Where .= "AND Segment3 = ";
		$Where .= implode(" OR Segment3 = ", $_POST['Segment3']);	
		$Where .= " ";
	}
}
 
Code:
function enquote($string){
 return "'" . mysql_real_escape_string($string) . "'";
}
if ($_POST['Segment3']) {
	if (count($_POST['Segment3']) > 0) {
		$Where .= "AND Segment3 IN ( ";
		$Where .= implode(",", array_map('enquote',$_POST['Segment3']));	
		$Where .= ")";
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top