shage Posted December 5, 2007 Share Posted December 5, 2007 if i have a large database full of sites, each site is under a category table such as electronic,clothes,etc im trying to export the information into a txt file that says Electronic Stores site A site B Clothes Stores site A site B im lost and new thank you Quote Link to comment https://forums.phpfreaks.com/topic/80281-txt-file-mysql/ Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 So what is the actual question? Do you have any code? Quote Link to comment https://forums.phpfreaks.com/topic/80281-txt-file-mysql/#findComment-406866 Share on other sites More sharing options...
shage Posted December 5, 2007 Author Share Posted December 5, 2007 only code i have now prints out every link Quote Link to comment https://forums.phpfreaks.com/topic/80281-txt-file-mysql/#findComment-406875 Share on other sites More sharing options...
revraz Posted December 5, 2007 Share Posted December 5, 2007 Post it for people can help you fix it. Quote Link to comment https://forums.phpfreaks.com/topic/80281-txt-file-mysql/#findComment-406880 Share on other sites More sharing options...
chocopi Posted December 5, 2007 Share Posted December 5, 2007 I think this might be what you are looking for. It basically goes through all the tables in your database and then takes the column sitename (which obviusly you will need to change to suit your needs) and goes through each value. It is all added to the variable $string which is then written into the db.txt which you will need to create one and name it what ever you want. <?php $db_host = ''; $db_username = ''; $db_password = ''; $db_database = ''; $db_connection = mysql_connect($db_host,$db_username,$db_password) or die(mysql_error()); mysql_select_db($db_database) or die(mysql_error()); $string = ""; $sql = "SHOW TABLES FROM $db_database"; $result = mysql_query($sql) or die(mysql_error()); while($table_name = mysql_fetch_array($result)) { $sql2 = "SELECT sitename FROM $table_name[0]"; $result2 = mysql_query($sql2) or die(mysql_error()); $string .= "\n{$table_name[0]}\n"; while($column_name = mysql_fetch_array($result2)) { $string .= "{$column_name[0]}\n"; } } $file = "db.txt"; if(is_writable($file)) { if(!$handle = fopen($file, 'w')) { die("Cannot open file ($file)"); } if(fwrite($handle, $string) === FALSE) { die("Cannot write to file ($file)"); } echo "Success, wrote to file ($file)"; fclose($handle); } else { echo "The file $file is not writable"; } ?> I hope it helps ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/80281-txt-file-mysql/#findComment-406940 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.