elentz Posted September 17, 2017 Share Posted September 17, 2017 The goal of this whole exercise is to take info from a table and create a text file with the inormation. For example in the table: info1 = name info2 = address info3 = city I need the text file to have in it; Your name is $info1 your address is $info2 you live in $info3 How do I get started doing this? Thanks for any help Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted September 17, 2017 Share Posted September 17, 2017 Create a string first. When that's done, you can take care of writing the string to a file. I hope the columns aren't literally named “info1”, “info2”, “info3”? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 17, 2017 Share Posted September 17, 2017 Have you begun your script yet? Do you have error checking turned on for your development? Do you have a database connection setup yet? Have you written the query that will get the data from the table? You have many things to think about here. Better get started with them before you ask how it's done here. We won't write it for you but we will help you make it work. Quote Link to comment Share on other sites More sharing options...
elentz Posted September 18, 2017 Author Share Posted September 18, 2017 Jacques1, I was just using a simple example. ginerjm, The DB connection adn the queries and that I can do. I'll get a script together. I use your error reporting in your sig in all my scripts. Quote Link to comment Share on other sites More sharing options...
elentz Posted September 18, 2017 Author Share Posted September 18, 2017 Ok so now I can connect and get info to a php page. <?php include('/var/www/html/cqadmin/menu.html'); ?> <p>Write Test Page</p> <hr> <?php error_reporting(E_ALL); ini_set('display_errors','On'); require('/var/www/html/cqadmin/utils/connect.php'); $sql = "SELECT * from templateinfo where id = 47"; $result = mysqli_query($link,$sql) or die(mysql_error()); while ($row = mysqli_fetch_assoc($result)) { echo $row['templatename']; echo $row['keyname1']; echo $row['lk1']; echo $row['lk1value']; } ?> So I should be able to use the $row['keyname1'] as the variable to use in the Write to the file, along with all the other field entries. I have a script that uses $POST data at the moment to write the file. $fh = fopen("/var/www/html/cqadmin/Templates/$template.cfg", 'w') or die("can't open file"); $firstline = "#!version:1.0.0.1"; $stringData = "$firstline\n"; fwrite($fh, $stringData); // LineKeys $stringData = "linekey.1.type= $lk1type\n"; fwrite($fh, $stringData); $stringData = "linekey.1.value= $lk1value\n"; fwrite($fh, $stringData); $stringData = "linekey.1.label= $lk1label\n"; fwrite($fh, $stringData); $stringData = "linekey.1.line= 1\n"; Would applying $row['lk1value1'] instead of $lk1value be the way to go? Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 18, 2017 Share Posted September 18, 2017 Would applying $row['lk1value1'] instead of $lk1value be the way to go? You could modify the code for writing to a file so that it's a function. Then just pass the data. That way it wouldn't matter how you name the variables. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 18, 2017 Share Posted September 18, 2017 (edited) I like the suggestion to create an output function. But since you asked.... Where is $lk1value even created? I don't see it. And - do your php at the top; do your html at the bottom. Therefore You should look something like this in your first block <?php error_reporting(E_ALL); ini_set('display_errors','On'); require('/var/www/html/cqadmin/utils/connect.php'); $sql = "SELECT * from templateinfo where id = 47"; $result = mysqli_query($link,$sql) or die(mysql_error()); $output = ''; while ($row = mysqli_fetch_assoc($result)) { $output .= $row['templatename']; $output .= $row['keyname1']; $output .= $row['lk1']; $output .= $row['lk1value']; $output .= "\n"; } include('/var/www/html/cqadmin/menu.html'); // // Done with PHP logic - now output html and variables // $heredocs =<<<$code <p>Write Test Page</p> <hr> $output heredocs; echo $code; Note the absence of php mode tags in and out of the script. Note the placement of the html where it is NEEDED, not where you feel it necessary. Read up on the use of 'heredocs' in the manual PS - sorry about the double spacing. The forum seems to do that to me all the time. Edited September 18, 2017 by ginerjm Quote Link to comment Share on other sites More sharing options...
elentz Posted September 18, 2017 Author Share Posted September 18, 2017 The $lk1value was a variable in the original script to write to the file using $Post information. There will be about 80 variables There will not be any html in the final script. I just used that to make sure I was getting info from the table. How would a output function work? The script is for creating a conf file for a template for a IP phone. I'll lookup heredocs. Thanks Quote Link to comment 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.