function makeRow($section, $key, $value, $tab = 0)
{
    $ret = '';
    if (is_integer($key)) {
        for ($i = 0; $i < $tab; $i++) {
            $value = '&nbsp;' . $value;
        }
        $ret = '<tr>';
        $ret .= '<td class="key">' . $value . '</td>';
        ob_start();
        ?>
            <td class="filler">
                <input type="number" min="0" class="count" name="value" data-key="<?php 
        echo md5($section . $value);
        ?>
">    
            </td>
        <?php 
        $ret .= ob_get_clean();
        $ret .= '</tr>';
    } else {
        if (is_string($key)) {
            $ret .= makeRow($section, 0, $key);
            if (is_array($value)) {
                foreach ($value as $k => $v) {
                    $ret .= makeRow($section, $k, $v, $tab + 8);
                }
            }
        }
    }
    return $ret;
}
function makeRows($files)
{
    $rows = "";
    foreach ($files as $file) {
        $extension = fileExtension($file);
        if ($extension != "") {
            $row = makeRow($file, $extension);
            $rows = "{$rows}{$row}\n";
        }
    }
    return $rows;
}
Exemple #3
0
// Output: Copy of input row, except keys renamed to php scheme and columns
//         limited to those listed in keyMap.
$dbRowGlobal;
//  Simulate static scope in nested functions below.
//  Probably cleaner to use global approach in 1st place.
function makeRow(&$dbRow)
{
    global $keyMap;
    global $dbRowGlobal;
    //TODO: Figure out how to assign by reference/pointer.
    $dbRowGlobal = $dbRow;
    $getMappedValue = function ($mappedKey) {
        global $dbRowGlobal;
        return $dbRowGlobal[$mappedKey];
    };
    return array_map($getMappedValue, $keyMap);
}
// ============================================================================
// Load data into a php array; return from script w/ JSON encoding of array.
// ============================================================================
// Build array of rows like array('id'=>Id, 'fn'=>FirstName, 'ln'=>LastName).
//TODO: Verify interface w/ db, get rid of fakeTable.
//STUB: $entryList = array_map($makeRow, $fakeTable);
$entryList = [];
while ($row = mysql_fetch_assoc($queryResult)) {
    $entryList[] = makeRow($row);
}
// Return JSON encoding of entryList; it is unnecessary to build JSON string.
echo json_encode($entryList);
// Close connection to the MySQL server process.
mysql_close();
Exemple #4
0
            $aTmp['NO'] = intstring($i++);
            $aTmp['dirname'] = $file;
            $aTmp['author'] = $setting['author'];
            $aTmp['name'] = $setting['name'];
            $aTmp['version'] = $setting['version'];
            $aTmp['catalog'] = $setting['catalog'];
            $aTmp['create'] = $setting['stime'];
            $aTmp['description'] = $setting['description'];
            $rowstr .= makeRow($aTmp);
            unset($setting);
        }
    }
    closedir($handle);
}
$header = array_keys($aTmp);
$header = makeRow($header);
$rowstr = $header . $rowstr;
makeTable($rowstr);
function makeTable($rowstr)
{
    echo <<<EOF
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
\t\t<table border='1'>
\t\t{$rowstr}
\t\t</table>
</body>
</html>
Exemple #5
0
// Input: Row of db table.
// Precondition: The input row has columns named like values of keyMap.
// Output: Copy of input row, except keys renamed to php scheme and columns
//         limited to those listed in keyMap.
$dbRowGlobal;
//  Simulate static scope in nested functions below.
//  Probably cleaner to use global approach in 1st place.
function makeRow(&$dbRow)
{
    global $keyMap;
    global $dbRowGlobal;
    //TODO: Figure out how to assign by reference/pointer.
    $dbRowGlobal = $dbRow;
    $getMappedValue = function ($mappedKey) {
        global $dbRowGlobal;
        return $dbRowGlobal[$mappedKey];
    };
    return array_map($getMappedValue, $keyMap);
}
// ============================================================================
// Load data into a php array; return from script w/ JSON encoding of array.
// ============================================================================
// Build array of rows like array('id'=>Id, 'fn'=>FirstName, 'ln'=>LastName).
//STUB: $entryList = array_map($makeRow, $fakeTable);
$mysqlRow = mysql_fetch_assoc($queryResult);
$phpRow = makeRow($mysqlRow);
$phpArray = [$phpRow];
// Return JSON encoding of entryList; it is unnecessary to build JSON string.
echo json_encode($phpArray);
// Close connection to the MySQL server process.
mysql_close();
Exemple #6
0
function upLoad()
{
    //Funktion som skickar en sträng till arduinon.
    $name = $_REQUEST["name"];
    //type,name,checksum,temp,
    $temp = $_REQUEST["temp"];
    //checksum = strlen(name)+temp
    if (preg_match("/[a-zA-ZåäöÅÄÖ0-9]+/", $name)) {
        if (preg_match("/[0-9]+/", $temp)) {
            $text = "cooling,";
            $check = strlen($name);
            $text .= $name;
            $id = makeRow($name);
            $text .= "," . $id;
            $check += $temp;
            $text .= "," . $check . "," . $temp . ",";
            $fp = fopen("/dev/ttyACM0", "w");
            if (!$fp) {
                echo "Can't find /dev/ttyACM0";
            }
            fwrite($fp, $text);
            echo "Scheme sent";
            fclose($fp);
            exec('python3 PythonPi.py');
        } else {
            echo "Invalid temp";
        }
    } else {
        echo "Invalid namn";
    }
}
<html> 
<head><title>PHP Table</title></head> 
<style> 
    table{border-collapse: collapse;margin-left:auto;margin-right:auto;width:85%} 
    td{border: 1px solid black;text-align:center;font-weight:bold;} 
</style> 
<body> 
<h1> PHP Script to display Strings of value within a table: </h1>

    <table> 
    <?php 
makeRow("Mr. Fresh", "\$1,000.00");
makeRow("Ms. Soft", "\$1,500.00");
makeRow("Mrs. Senior", "\$2,500.00");
function makeRow($name, $salary)
{
    echo "<tr>";
    echo "<td>Salary of " . $name . " is</td>";
    echo "<td>" . $salary . "</td>";
    echo "</tr>";
}
?>
 
    </table> 
	<br/><br/>
  <h4> <a href="php1.php">PHP Validations</a> | <a href="php2.php">PHP Array</a> | <a href="php4.php">String in Table</a> | <a href="php5.php">Prime Number</a> |  <a HREF="/~vjavvaji1/index.html">Home</a>| </h4>
</body> 
</html>
Exemple #8
0
function upLoad()
{
    $boilTemp = $_REQUEST["temp"];
    $wElements = $_REQUEST["wElements"];
    $mWarm = $_REQUEST["mWarm"];
    //Funktion som skickar en sträng till arduinon.
    $name = $_REQUEST["name"];
    //name,temp1,time1,temp2,time2....tempn,timen,checksum
    $array = json_decode($_REQUEST["array"]);
    //checksum = strlen(name)+temp1+time1+temp2+...+tempn+timen
    $total = $_REQUEST["total"];
    if (preg_match("/[a-zA-ZåäöÅÄÖ0-9]+/", $name)) {
        if (preg_match("/[0-9]+/", $total)) {
            if (!empty($array)) {
                $text = "boil,";
                $check = strlen($name);
                $text .= $name;
                $id = makeRow($name, $wElements, $mWarm);
                $text .= "," . $id;
                $check += count($array);
                $check += $total;
                $check += $boilTemp;
                $temp = "";
                for ($i = 0; $i < count($array); $i++) {
                    $temp .= "," . $array[$i][0];
                    $temp .= "," . $array[$i][1];
                    $check += strlen($array[$i][0]);
                    $check += $array[$i][1];
                }
                $text .= "," . $wElements . "," . $mWarm;
                $text .= "," . $check . "," . count($array) . "," . $boilTemp . "," . $total;
                $text .= $temp . ",";
                $fp = fopen("/dev/ttyACM0", "w");
                if (!$fp) {
                    echo "Can't find /dev/ttyACM0";
                }
                fwrite($fp, $text);
                echo "Scheme sent";
                fclose($fp);
                exec('python3 PythonPi.py');
            } else {
                echo "Arrayen tom";
            }
        } else {
            echo "Total time invalid";
        }
    } else {
        echo "Invalid namn";
    }
}