Jump to content

Compare Lists


phpretard

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.