brooksh Posted March 25, 2008 Share Posted March 25, 2008 I'm not sure why this isn't working. I am selecting multiple checkboxes, and having the next step search based on those selections. The first step I select States and want to find out counties associated with the states selected. But it doesn't work. for( $i=0; $i<count($_POST['State']); $i++ ) { $State1 .= $_POST['State'][$i] . ","; } $str_temp_len=strlen($State1); $State1=substr($State1,0,($str_temp_len-1)); $sql = "select DISTINCT county from zip_codes where state_prefix = '$State1' order by county"; $result = mysql_query ($sql); Quote Link to comment Share on other sites More sharing options...
brevig Posted March 25, 2008 Share Posted March 25, 2008 Couple of things: Can you edit this line $result = mysql_query ($sql); to $result = mysql_query ($sql) or die( $sql."<br />".mysql_error() ); Run that and then copy/paste the error msg here. -- I just guessing now, but if you are looking for a distinct county based on state prefix you might want to make a couple changes to your code, fun it and post results here. for( $i=0; $i<count($_POST['State']); $i++ ) { if( !isSet( $State1 ) ){ $State1 = "( '{$_POST['State'][$i]}' "; }else{ $State1 .= ", '{$_POST['State'][$i]}' "; }//end if } $State1 .= " ) "; $sql = "SELECT DISTINCT z.county, z.state_prefix FROM zip_codes z WHERE z.state_prefix in {$State1} GROUP BY z.count, z.state_prefix"; $result = mysql_query ($sql) or die( $sql."<br />".mysql_error() ); while( $row = mysql_fetch_array( $result, MYSQL_ASSOC() ) { echo $row['county']." ".$row['state;]."<br />"; }//end while loop mysql_free_result( $result ); $row = array(); $State1 = $sql = $result = $row = null; unset( $State1, $sql, $result, $row ); exit('fin'); Let me know how that turns out! You can also get low cost php support at www.phpsupportnow.com Good luck Quote Link to comment Share on other sites More sharing options...
brooksh Posted March 25, 2008 Author Share Posted March 25, 2008 It works. Thanks. 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.