Question

In: Computer Science

How would I structure the following PHP (PDO) code into a table format using only PHP?...

How would I structure the following PHP (PDO) code into a table format using only PHP?

//Our SQL statement, which will select a list of tables from the current MySQL database.
$sql = "SELECT * FROM jobs";

//Prepare our SQL statement,
$statement = $pdo->prepare($sql);

//Execute the statement.
$statement->execute();

//Fetch the rows from our statement.
$tables = $statement->fetchAll(PDO::FETCH_NUM);

//Loop through our table names.
foreach($tables as $table){
//Print the table name out onto the page.
echo $table[0], '
';
echo $table[1], '
';
echo $table[2], '
';
echo $table[3], '
';
echo $table[4], '
';
  
}

Solutions

Expert Solution

If you have any doubts, please give me comment...

<?php

$servername = "localhost";

$username = "username";

$password = "password";

$dbname = "myDB";

try {

$pdo = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = "SELECT * FROM jobs";

//Prepare our SQL statement,

$statement = $pdo->prepare($sql);

//Execute the statement.

$statement->execute();

//Fetch the rows from our statement.

$tables = $statement->fetchAll(PDO::FETCH_NUM);

//Loop through our table names.

echo "<table>";

foreach($tables as $table){

//Print the table name out onto the page.

echo "<tr><td>".$table[0]. "</td><td>".$table[1]."</td><td>".$table[2]."</td><td>".$table[3]."</td><td>".$table[4]."</td></tr>";

}

echo "</table>";

}

catch(PDOException $e) {

echo "Error: " . $e->getMessage();

}

?>


Related Solutions

C++ Code! This code was written/implemented using the "class format." How would I go about in...
C++ Code! This code was written/implemented using the "class format." How would I go about in converting it to the "struct format?" #include <iostream> #include <iomanip> using namespace std; class ListNode{ public: string course_name; string course_number; string course_room; ListNode* next; ListNode(){ this->next = NULL; } ListNode(string name, string number, string room){ this->course_name = name; this->course_number = number; this->course_room = room; this->next = NULL; } }; class List{ public: ListNode* head; List(){ this->head = NULL; } void insert(ListNode* Node){ if(head==NULL){ head...
PHP Language I have XAMPP and I don't know how to display my PHP code. For...
PHP Language I have XAMPP and I don't know how to display my PHP code. For instance, when I create a basic HTML webpage I just open the code into a web browser and it shows me a basic web page. When I try to show a PHP calculation it doesn't show. What are the steps in displaying my PHP doc?
In which folder of XAMPP would I put in my PHP code
In which folder of XAMPP would I put in my PHP code
I need to understand how I would edit this code without changing anything, only adding. I...
I need to understand how I would edit this code without changing anything, only adding. I am not looking for the exact answer, just information on how I would use the given code to complete some of the todo statements. Thank you! // include this header file so we can use `printf()` #include <stdio.h> // every C program must implement the `main()` function int main(int argc, char *argv[]) {    //TODO: check for enough arguments       // save the...
how to read a csv file in php and make a html table? I can't use...
how to read a csv file in php and make a html table? I can't use the PHP function fgetcsv. I can use explode. I can't put a php inside a php. Acme,Walmart,Ross,BJs,Target,Marshalls,Foot Locker,Giant,Charming Charlie 142,160,28,10,5,3,60,0.28,3167 175,180,18,8,4,1,12,0.43,4033 129,132,13,6,3,1,41,0.33,1471 138,140,17,7,3,1,22,0.46,3204 232,240,25,8,4,3,5,2.05,3613 135,140,18,7,4,3,9,0.57,3028 150,160,20,8,4,3,18,4.00,3131 207,225,22,8,4,2,16,2.22,5158 271,285,30,10,5,2,30,0.53,5702 89,90,10,5,3,1,43,0.30,2054 153,157,22,8,3,3,18,0.38,4127 87,90,16,7,3,1,50,0.65,1445 234,238,25,8,4,2,2,1.61,2087 106,116,20,8,4,1,13,0.22,2818 175,180,22,8,4,2,15,2.06,3917 165,170,17,8,4,2,33,0.46,2220 166,170,23,9,4,2,37,0.27,3498 136,140,19,7,3,1,22,0.63,3607 <!DOCTYPE html> <html> <head>    <meta charset="utf-8">    <title>Stores</title>    <link rel="stylesheet" href="style.css"> </head> <body> <h1>Stores</h1> <?php <table> <tr> <th>Acme</th> <th>Walmart</th> <th>Ross</th> <th>BJs</th> <th>Target</th> <th>Marshalls</th> <th>Foot Locker</th>...
Hi, I would like the following python code rewritten in a different way/structure etc. I got...
Hi, I would like the following python code rewritten in a different way/structure etc. I got it from a question I posted but am worried fellow classmates will also be using it so am covering bases. her it is. #threeUniqueSongs.py #Simulation of professor listening to 3 songs out of playlist of 4 songs 10000 times sampling with replacement possible import random import math #Here playlist is the list of 4 songs i.e. "Eastside", "Better Now", "Lucid Dreams", "Harder, Better, Faster,...
How would I code the following in assembly language? Use the Keil programming environment to code...
How would I code the following in assembly language? Use the Keil programming environment to code the C8051F330 SiLabs 8051 micro controller. All the documentation is available on efundi. The program shall be done in assembler and you shall use the DJNZ instruction to generate a delay time to flash the LED. The LED shall flash in the following sequence: 1. On for 50mS, 2. Off for 400mS, 3. On for 50mS, 4. Off for 1.5S, 5. Repeat the sequence...
Using PHP and MYSQL and with a simple customer database, how can I create a simple...
Using PHP and MYSQL and with a simple customer database, how can I create a simple log in and registration system for an ecommerce site
How would I find the specific heat of a calorimeter? Using only a thermometer, water of...
How would I find the specific heat of a calorimeter? Using only a thermometer, water of various temperatures, and a scale. I need to explain a plan and derive an equation for it. Then use the same calorimeter and materials with some ice to find the latent heat of fusion of ice.
I want the code in the following three PHP files without any CSS. Thank you Create...
I want the code in the following three PHP files without any CSS. Thank you Create a Input.php. Create a PHP script that will perform the following tasks: 1. Divide the content area of this page into two sections (Side by Side) 2. On the left side: create a form that accepts the following information from the user a. Text box, Employee Name b. Text box, Employee ID c. Text box, Telephone Number d. Text box, Email Address e. Radio...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT