phpretard Posted August 2, 2008 Share Posted August 2, 2008 I promise this is NOT as compicated as it looks: CURRENT LIST IN TABLE: $sql = "SELECT * FROM members WHERE State='$State' ORDER by Counties"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $Counties2=str_replace(", ", "<li>", ($row['Counties'])); $County2 = explode("<li>", $Counties2); $CountyTotal = count($County2); } foreach ($County2 as $County1){ for ($i=0; $i<$CountyTotal; ++$i){ $County3="<div style='width:24%; float:left; font-size:13px;'><input type=checkbox name=Counties[] Value='$County1'>$County1</div>"; } }// CURRENT LIST OF COUNTIES LIST FROM A DIFFERENT TABLE: $result2 = mysql_query("SELECT DISTINCT County FROM ZipCodes WHERE State='$State' ORDER by County "); while($row = mysql_fetch_array($result2)) { $CountyList=$row['County']; $AllCounties="<div style='width:24%; float:left; font-size:13px;'><input type=checkbox name=Counties[] Value='$CountyList'>$CountyList</div>"; } // END ALL COUNTIES LIST /********COMPARE********/ if(stristr($County3, $AllCounties)) { $CHK="checked"; } /*****END COMPARE*******/ WHAT I THOUGHT WOULD CHECK THE BOXES: // LIST COMPARED RESULTS $result3 = mysql_query("SELECT DISTINCT County FROM ZipCodes WHERE State='$State' ORDER by County "); while($row = mysql_fetch_array($result3)) { $CountyAll=$row['County']; $AllCountiesCHK= "<div style='width:24%; float:left; font-size:13px;'><input type=checkbox name=Counties[] Value='$CountyAll' $CHK>$CountyAll</div>"; echo $AllCountiesCHK; } Well it doesn't ckeck the boxes. Any thought? Quote Link to comment Share on other sites More sharing options...
phpretard Posted August 2, 2008 Author Share Posted August 2, 2008 I should mention that all the code ran seperately works fine and the html outputs the same thing. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 2, 2008 Share Posted August 2, 2008 You've rather lost me there. I guess your trying to compare and see what information is in both tables? You can either do a left join, or you can read both result sets into an array and use array_intersect(). At present, you appear to be comparing outside of the loop. So unless you are using an array, that's not going to work. Perhaps if you told us exactly what you're trying to achieve, it would help some more. Quote Link to comment Share on other sites More sharing options...
phpretard Posted August 2, 2008 Author Share Posted August 2, 2008 Table 1 holds a select number of counties. Table 2 holds all the counties in the State. I want to display (in checkbox form) all the counties in the State from table 2 but have the select counties from table 1 checked. Understand? By the wat way do you want DB with that info in it? It's quite useful and I just bought it. It comes in lots of formats... Quote Link to comment Share on other sites More sharing options...
phpretard Posted August 2, 2008 Author Share Posted August 2, 2008 I don't know if this helps the cause but when I put this in the last loop all the boxes get checked: $result3 = mysql_query("SELECT DISTINCT County FROM ZipCodes WHERE State='$State' ORDER by County "); while($row = mysql_fetch_array($result3)) { $CountyAll=$row['County']; /////FROM HERE if(stristr($County3, $AllCounties)===FALSE) { $CHK="checked"; } /////TO HERE $AllCounties= "<div style='width:24%; float:left; font-size:13px;'><input type=checkbox name=Counties[] Value='$CountyAll' $CHK>$CountyAll</div>"; echo $AllCounties; } But only when set to FALSE. It should be obvious by now I am not sure what I need to do here. 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.