Jump to content

Need a starting point


elentz

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.