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...
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...
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
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...
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.
How would I go about making a simple code for an analog clock using matlab?
How would I go about making a simple code for an analog clock using matlab?
How do I find electron configuration using only the periodic table and what are some strategies?
How do I find electron configuration using only the periodic table and what are some strategies?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT