foreach ($row as $field => $value) { print "<th>{$field}</th>\n"; } print "</tr>\n"; //if a user enters a restaurant name, then query data from it. if (strlen($restaurant) > 0) { $query = "SELECT Restaurant.name as 'Restaurant',\n Cuisine.name as 'Cuisine',\n\t City.name as 'City',\n Price_Range.name as 'Price_Range'\n FROM Restaurant, Cuisine, City, Price_Range\n WHERE Restaurant.cuisine_fk = Cuisine.id\n AND Restaurant.city_fk = City.id\n AND Restaurant.price_range_fk = Price_Range.id\n AND Restaurant.name = :restaurant"; $ps = $con->prepare($query); $ps->bindParam(':restaurant', $restaurant); } else { $ps = $con->prepare($query); } $ps->execute(); $ps->setFetchMode(PDO::FETCH_CLASS, "Restaurant"); //prints each database row using ORM while ($r = $ps->fetch()) { print "<tr>\n"; createTableRow($r); print "</tr>\n"; } print "</table>\n"; } catch (PDOException $ex) { echo 'ERROR: ' . $ex->getMessage(); } ?> </div> </body> </html>
} print "</tr>\n"; //if a user enters a restaurant name, then query data from it. if (strlen($cuisine) > 0) { $query = "SELECT *\n\t\t\t\t FROM `Cuisine`\n\t\t\t\t\t WHERE `name` = :cuisine"; $ps = $con->prepare($query); $ps->bindParam(':cuisine', $cuisine); } else { $ps = $con->prepare($query); } $ps->execute(); $ps->setFetchMode(PDO::FETCH_CLASS, "Cuisine"); //prints each database row using ORM while ($c = $ps->fetch()) { print "<tr>\n"; createTableRow($c); print "</tr>\n"; } //$ps = $con->prepare($query); // debug - print $cuisine //print '$cuisine = '; //print $cuisine //print '<br>'; //$temp = array(':cuisine'=>$cuisine); // debug - print the array we feed to execute //var_dump($temp); //print '<br>'; // $ps->execute(array(':cuisine'=>$cuisine)); //$data = $ps->fetchAll(PDO::FETCH_ASSOC); // prints out the header for the table /* $header = true;
$query = "SELECT username \n FROM users\n NATURAL JOIN profiles"; $data = $con->query($query); $data->setFetchMode(PDO::FETCH_CLASS, "Lostname"); print " <table border='1'>\n"; $result = $con->query($query); $row = $result->fetch(PDO::FETCH_ASSOC); print " <tr>\n"; foreach ($row as $field => $value) { print " <th>{$field}</th>\n"; } print " </tr>\n"; if (strlen($firstName) > 0 && strlen($lastName) > 0) { $query = "SELECT username \n FROM users\n NATURAL JOIN profiles \n WHERE profiles.firstName = :firstName \n AND profiles.lastName = :lastName"; $ps = $con->prepare($query); $ps->bindParam(':firstName', $firstName); $ps->bindParam(':lastName', $lastName); } else { $ps = $con->prepare($query); } $ps->execute(); $ps->setFetchMode(PDO::FETCH_CLASS, "Lostname"); while ($lost = $ps->fetch()) { print " <tr>\n"; createTableRow($lost); print " </tr>\n"; } print " </table>\n"; } catch (PDOException $ex) { echo 'ERROR: ' . $ex->getMessage(); } print ' <p><button onclick="preparedBack()" id="backBtn">Back</button></p>';
} if (!in_array("branch", $empty_inputs, true)) { $sql = $sql . "({$branchSQL}='{$inputs['3']}' or {$branchSQL}='{$inputs['4']}' or {$branchSQL}='{$inputs['5']}') and "; } if (!in_array("month", $empty_inputs, true)) { $sql = $sql . "({$monthSQL}='{$inputs['6']}' or {$monthSQL}='{$inputs['7']}' or {$monthSQL}='{$inputs['8']}') and "; } if (!in_array("product", $empty_inputs, true)) { $sql = $sql . "({$productSQL}='{$inputs['9']}' or {$productSQL}='{$inputs['10']}' or {$productSQL}='{$inputs['11']}') and "; } $sql = $sql . "H.account_key = A.account_key and H.branch_key = B.branch_key and H.month_key = M.month_key and H.product_key = P.product_key group by {$accountSQL}, {$branchSQL}, {$monthSQL}, {$productSQL};"; $result = $con->query($sql); if ($result->num_rows > 0) { createTableHeaders(); while ($row = $result->fetch_array(MYSQLI_BOTH)) { createTableRow($row); } } else { echo "0 results"; } echo "</table>"; $con->close(); //end of file //creates table headers function createTableHeaders() { // global $accountHeader, $branchHeader, $productHeader, $monthHeader; // echo "<table id='actualBaseTable' class='center'> // <tr>"; // if(!($accountHeader == "")) // {echo "<th>$accountHeader</th>";}
$query = "SELECT firstName, lastName, day, startTime, endTime \n FROM availabilities NATURAL JOIN profiles"; // Fetch the matching database table rows. $data = $con->query($query); $data->setFetchMode(PDO::FETCH_CLASS, "Person"); // We're going to construct an HTML table. print " <table border='1'>\n"; // Fetch the database field names. $result = $con->query($query); $row = $result->fetch(PDO::FETCH_ASSOC); // Construct the header row of the HTML table. print " <tr>\n"; foreach ($row as $field => $value) { print " <th>{$field}</th>\n"; } print " </tr>\n"; // Prepare query $ps = $con->prepare($query); // Fetch the matching database table rows. $ps->execute(); $ps->setFetchMode(PDO::FETCH_CLASS, "Person"); // Construct the HTML table row by row. while ($person = $ps->fetch()) { print " <tr>\n"; createTableRow($person); print " </tr>\n"; } print " </table>\n"; } catch (PDOException $ex) { echo 'ERROR: ' . $ex->getMessage(); } print ' <p><button type="button" onclick="preparedBack()" id="backBtn">Back</button></p>';
{ return $num1 === $num2; } function createTableRow($row) { $html = '<tr>'; $html .= createTableCell($row, 'factor'); for ($column = 0; $column <= 12; $column++) { $grid = $row * $column; if (isSquare($row, $column)) { $html .= createTableCell($grid, 'squarenum'); } else { $html .= createTableCell($grid, 'plain'); } } $html .= '</tr>'; return $html; } $html = '<table>'; $html .= '<tr>'; $html .= '<td>'; $html .= '</td>'; for ($headcolumn = 0; $headcolumn <= 12; $headcolumn++) { $html .= createTableCell($headcolumn, 'factor'); } $html .= '</tr>'; for ($row = 0; $row <= 12; $row++) { $html .= createTableRow($row); } $html .= '</table>'; echo $html;