brooksh Posted February 17, 2008 Share Posted February 17, 2008 How can this be accomplished? I know the code below is completely unrealistic, but how can it be done? SELECT DISTINCT City FROM listings WHERE area = 'array($_POST[area])' order by City Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 17, 2008 Share Posted February 17, 2008 <?php $array= array($_POST['area']); $sql="SELECT DISTINCT City FROM listings WHERE area=$array ORDER BY City"; mysql_query($sql);?> Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 If $_POST['area'] is an array of areas eg array('x', 'y', 'z') then <?php $areas = join ("','", $_POST['area']); $sql="SELECT DISTINCT City FROM listings WHERE area IN ('$areas')"; Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 17, 2008 Share Posted February 17, 2008 <?php $areas = join ("','", $_POST['area']); $nested_array=serialize($areas); $make_safe_query=mysql_real_escape_string($nested_array); $sql="SELECT DISTINCT City FROM listings WHERE area IN ('$areas')";?> adding onto it. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 17, 2008 Share Posted February 17, 2008 Why serialize a string? Quote Link to comment Share on other sites More sharing options...
brooksh Posted February 17, 2008 Author Share Posted February 17, 2008 I am running php 4.3 and I don't know if that's why I'm getting this error. Warning: join() [function.join]: Bad arguments. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted February 17, 2008 Share Posted February 17, 2008 <?php $areas = array( $_POST['area']); $comma_seperated=implode(",",$areas); $nested_array=serialize($comma_seperated); $make_safe_query=mysql_real_escape_string($nested_array); $sql="SELECT DISTINCT City FROM listings WHERE area IN ('$make_safe_query')"; mysql_query($sql); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.