Jump to content

jcac

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jcac's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to create a page that allows people to backup their database on a web page but I'm having trouble with the ending of it. <?php require("../include/config.php"); $tables = array(); $qTables = mysql_query("SHOW TABLES"); while($row = mysql_fetch_row($qTables)) { $tables[] = $row[0]; } foreach($tables as $tab1) { $return.= "DROP TABLE IF EXISTS `".$tab1."`;"; $row2 = mysql_fetch_row(mysql_query("SHOW CREATE TABLE `" . $tab1 . "`")); $return.= "\n\n".$row2[1].";\n\n"; $result = mysql_query("SELECT * FROM ".$tab1) or die(mysql_error()); $num_fields = mysql_num_fields($result); $return.= "INSERT INTO `".$tab1."`"; $col = mysql_query('SELECT * FROM '.$tab1); $a = 0; $return.= " ("; while ($a < mysql_num_fields($col)) { $meta = mysql_fetch_field($col, $a); $return.= "`" . "$meta->name"; $a++; if ($a < mysql_num_fields($col)) { $return.= "`,"; } else { $return.= "`"; } } $return.= ")"; $return.=" VALUES\n("; for ($i = 0; $i < $num_fields; $i++){ while($row = mysql_fetch_row($result)){ for($j=0; $j<$num_fields; $j++){ if (isset($row[$j])) { $return.= "'".$row[$j]."'" ; } else { $return.= "''"; } if ($j < ($num_fields-1)) { $return.= ","; } if (j < ($num_fields-1)){ $return.= "),\n("; } else { $return.= ");\n"; } } } } } $handle = fopen("db-backup-".time()."-".(md5(implode(",",$tables))).".sql","w+"); fwrite($handle,$return); ?> At this part: if (j < ($num_fields-1)){ $return.= "),\n("; } else { $return.= ");\n"; } If it has finished going through all of the values it will put ); at the end and if it hasn't it will put ), and then continue with the next one. The problem I'm having is it's only doing the ), Can someone help me please?
×
×
  • 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.