Jump to content

[SOLVED] need help


Nandini

Recommended Posts

I am doing a website using php and mysql.

 

I want to generate .conf files when click button with names of database values.

for example: there is a database table named as "config". In that there is a field "trunkname" that is unique. I want to click .conf files when click submit like extension. trunkname value here.con, etc.

If "config" table have 3 rows. Trunknames are value1,value2,value3.

Then i the script generate 3 files named as extension.value1.conf,extension.value2.conf and extension.value3.conf  files with individual data.

 

I have generated files with my script. But total table data was inserted into each file. but i want to insert individual data into individual file. here is my script.

 

<?

$ext_content[] = "; do not edit this file, this is an auto-generated file";

$ext_content[] = "; all modifications must be done from the web GUI";

$ext_content[] = "";

$ext_content[] = "";

$sql_trunkname=mysql_query("select * from sip");

while($row_trunkname=mysql_fetch_array($sql_trunkname)) {

$trunk_name[]=$row_trunkname['trunk'];

}

foreach($trunk_name as $v) {

$file_sipext="extensions.$v.conf";

 

$path_sipext=$dh.$file_sipext;

`sudo chmod 777 $path_sipext`;

 

$create_sipext=fopen($path_sipext,"w+");

$ext_content[] = $v;;

$data_ext = implode("\n", $ext_content);

file_put_contents($path_sipext, $data_ext);

fclose($create_sipext);

if($create_sipext) {

echo "files generated";

} else {

echo "files not generated";

}

}

?>

 

help me out. Its utgent. Client waiting there.

 

Link to comment
https://forums.phpfreaks.com/topic/119809-solved-need-help/
Share on other sites

The explanation isnt very clear and i dont get what u need this for. From a brief look, the code looks ok, but i would rather simplify it:

 

<?php
$results = mysql_query("SELECT * FROM sip");
while($values = mysql_fetch_array($results)){
     $file = 'extensions' . $values['trunk'] . '.conf';
     $content = 'some random content for :' . $values['trunk'];
     $handle = fopen($file, 'w');
     fwrite($handle, $content);
     fclose($handle);
}
?>

 

A more simplified version without the need of running 2 loops.

Link to comment
https://forums.phpfreaks.com/topic/119809-solved-need-help/#findComment-617258
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.