I have two tables that I have linked together in a query. The assignments table holds the template assigned to a phone. The templateinfo table holds all the template settings, there is a templatename within the templateinfo. I have a script that creates a file from the inner join. IF I input by hand the name of a specific template the script runs find and creates the correct number of files. My issue is that I need to query the assignments table for the different names of the templates and use it in the inner join to create the files. There could be any number of template names that need to be applied. Here is what I have now, th ere is a template name of "Wednesday" that will create ALL the files needed for the phones that have been assigned with the Wednesday templates.
<?php
require('/var/www/html/cqadmin/utils/connect.php');
// Check connection
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}
// attempt insert query execution
$sql = "INSERT INTO assignments
(extension, secret, macaddress, template)
VALUES (?,?,?,?)";
$result = $link->prepare($sql);
foreach ($_POST['extension'] as $idx => $extension) {
$result->bind_param('ssss',
$extension,
$_POST['secret'][$idx],
$_POST['phone'][$idx],
$_POST['template'][$idx]
);
if( $result->execute() ) {
echo "Records $idx added successfully.";
} else{
echo "ERROR: Could not execute $sql. " . $result->error;
exit;
}
}
$sql2 = "select template from assignments";
$result2 = $link->query(sql2);
$sql = "SELECT * FROM templateinfo INNER JOIN assignments ON template = templatename where assignments.template= Wednesday";
$result = $link->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc())
{
The rest of the script creates files using fwrite.
Thanks for looking