I have this function below and it takes in the id of the article and the table its from in the database.
The first query will return a string like so ;1|;4|;7|;8| which is assigned to $format_array, what im trying to do in the second query and loop is to check the id returned from each row of review_format table and if its equal to one of the numbers in the $format_array that it will echo out to screen "checked".
The first query will return a string like so ;1|;4|;7|;8| which is assigned to $format_array, what im trying to do in the second query and loop is to check the id returned from each row of review_format table and if its equal to one of the numbers in the $format_array that it will echo out to screen "checked".
Code:
function display_edit_format($id,$table) {
$sql = mysql_query("SELECT format FROM ".$table." WHERE id=".$id."");
while ($row = mysql_fetch_array($sql))
{
$i = 0;
$format_array = $row['format'];
$array_size = sizeof($format_array);
$sql = mysql_query("SELECT id,description FROM review_formats");
while ($row = mysql_fetch_array($sql))
{
echo'<input type="checkbox" name="format[]" value=";'.$row['id'].'|" class="form"';
for($i = 0;$i < $array_size;$i++)
{
if($row['id'] == $format_array[$i])
{
echo' checked';
}
}
echo'>'.$row['description'].'<br>';
}
}
}