I'm trying to parse an entire MySQL table into files named after the rows. However, it seems to miss out a lot of files, and it just isn't working properly, but I don't understand what's wrong. Here's what I'm using:
$link = mysql_connect(...); //*Let's assume this is correct*
mysql_select_db(*This too*);
$query = "SELECT * FROM rules";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result) or die(mysql_error());
for($x = 0;$x < $num;$x++) {
$rules = mysql_fetch_assoc($result);
$file = '';
if($rules['except'])
$file .= $common = str_replace(explode(',', $rules['except']), "", $common);
if($rules['custom'])
$file .= $rules['custom'];
if($rules['css'])
$file .= trim($rules['css'], ";")."{display:none !important;height:0px !important;width:0px !important;}";
if($file == '') {
$handle = fopen($rules['site'].'.css', 'w');
fwrite($handle, $file);
}
}
Can anyone see anything wrong?