MySql to txt with PHP -
i have problem. googled couldn't find answer. so, have website users can add creations. creations going in mysql table. now, want take data table , send .txt file,but, want save in txt file title have in table. mysql table has 4 columns:
creations, title, user , categories.
i want save each row table in separate text file title title column. or, when user click on post creation not send database send directly text file title add.
this postcreations.php
if ($_post['posteaza']) { $con=mysqli_connect("localhost", $uname, $password,$database) or die (" nu ma pot conecta"); mysqli_query($con,"create table if not exists postest (id int(255) not null auto_increment primary key, continut varchar(10000000), titlul varchar(200), categorie varchar(200), user varchar(30))") or die (" nu pot crea"); $text = mysqli_real_escape_string($con,(stripslashes($_post['continut']))); $titlul = mysqli_real_escape_string($con,(stripslashes($_post['titlul']))); $categorie=mysqli_real_escape_string($con,(stripslashes($_post['categorii']))); $user=$_post['username']; if($text!=null && $titlul!=null) mysqli_query($con,"insert postest(continut,titlul,categorie,user) values ('$text','$titlul','$categorie','$username')") or die ('error updating database');
and how i'm taking out:
$con=mysqli_connect("localhost",$name,$password,$database) or die("nu se poate deschide baza de date"); $query = "select * postest1"; $result = mysqli_query($con,$query); while($row = mysqli_fetch_array($result)){ //creates loop loop through results echo "<table><tr><td>" . $row['titlul'].", de ".$row['user']."</td><td></table>"; //$row['index'] index here field name
here ye' go
<?php //connect database insert following $result = mysqli_query($conn, "select creations, title, user, categories people id = '42'"); if (!$result) { echo 'could not run query: ' . mysqli_error(); exit; } while($row=mysqli_fetch_array($result)) { $fp = fopen($row["title"].'.txt', 'w'); fwrite($fp, "creation:".$row["creations"].",title:".$row["title"].",user:".$row["user"].",catagories:".$row["catagories"]); fclose($fp); }
Comments
Post a Comment