Can anyone help me out.
I've currently got a comma seperated value stored in a field within my db.
From here I am then returning the field as a string and using explode() to put this in to an array and populating some check boxes using the array search.
What I have found however is that anything stored in the first element of the array i.e array[0] is not found.
To give an example:
array(0 => 1, 1 => 10); Only 10 is returned
array(0 => 10); No value is returned
The code I am using is this:
// Create array for industry
$industry = explode(",", $industry);
// SQL query
$sql = "SELECT * FROM industry";
// Execute SQL and exit if failure
$sql_result = mysql_query($sql) or die(mysql_error());
// Tabulate data using count variable
echo '<table>';
echo '<tr>';
while ($row = mysql_fetch_assoc($sql_result)){
if(array_search($row['id'], $industry) == true){
echo '<td><input type="checkbox" name="industry[]" value="'.$row['id'].'" checked />'.$row['industry'].'</td>';
} else {
echo '<td><input type="checkbox" name="industry[]" value="'.$row['id'].'" />'.$row['industry'].'</td>';
}
$i++; # increment counter
if ($i > $cols){ //create new row
echo '</tr><tr>';
$i = 1;
}
}