strpos Not working as expected

Discussion in 'PHP' started by abrown72, Aug 25, 2008.

  1. #1
    Hey all,

    I have a table that has multiple CSV's like so 12, 18, 19 my code
    <?php
    require("mysql_connect.php");
    $data = mysql_query("SELECT * FROM review_treatment_area");
    while($row = mysql_fetch_array($data))
    {
    $check_reviewArea = $row[area_id].", ";
    $pos = strpos($f_area, $check_reviewArea);

    if ($pos === False)
    {
    echo "<input type='checkbox' name='sel_group_area[]' value='".$row[area_id]."' />".$row[area_name]."<br />";
    }
    else
    {
    echo "<input type='checkbox' name='sel_group_area[]' value='".$row[area_id]."' checked />".$row[area_name]."<br />";
    }
    }
    ?>
    The issue I am having is if a table has the values 12, 18, 19 in it the dynamically generated checkboxes shown in the code above end up with checked values of 8, 9, 12, 18, 19 instead of just 12, 18, 19, and for the life of me I can't figure out a solution.

    Any help would be great!
     
    abrown72, Aug 25, 2008 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    You can store your values with commas on both sides, without spaces, i.e.
    so your $check_reviewArea can be

    $check_reviewArea = ','.$row['area_id'].',';
    PHP:
     
    wmtips, Aug 25, 2008 IP
  3. abrown72

    abrown72 Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey thats perfect, I see now. Thanks!
     
    abrown72, Aug 26, 2008 IP