PHP Homework Help | Practice Sample Set



Requirement Details

Let there be database tables.

Rely on XAMPP and create the database table locally. You need to create a database called “assignment8” programmatically. Please submit the “create database” and “create table” sql commands, either through your init.php or if done separately, please submit it through a .sql file. In case you have a .sql file, please make sure that you are calling it from your .php file. I will need only to run your index.php and it should run the init.php which, if required, would run the .sql file.


Now that you have the details on how to connect to the database, you need to create a table that replicate the input.csv structure from last assignment; i.e. every column in that table needs to be translated into a column in the database.


Within your program, you need to open the input.csv file, read its content and every row in this csv table needs to be populated inside the database table you have created.


So, in summary, here is what you need to do:

  • Create a database called “assignment8”

  • Create a table named “Items”

  • Within this table, create the following columns


Structure for Items Table

Name Type Length/Values Default Attributes

ID INT 6 NONE Unsigned, auto_increment, primary key

Name VARCHAR 40 NONE

Type VARCHAR 40 NONE

Make VARCHAR 40 NONE

Model VARCHAR 40 NONE

3

Brand

VARCHAR

40

NONE


Description

VARCHAR

60

NONE


- Read the content of “input.csv” file and populate with it the rows of “items” table

- You need to create these columns from within a php page and for this reason, you need to create a file called init.php and use the examples in the slides or any other resource provided, to create the columns

o You run this file once only, since the database management system (DBMS) will create them once and they will be there for you anytime you access them

o Within your init.php, you need to insert the rows for each entry you have created in input.csv

- So, in summary, init.php will create the database, connect to it, create the table with the columns list provided above and populate this table with records read from the content of the file “input.csv”.

- You can use the default template provided for “input.csv” or even better, update this content with what you have been building through the whole course in term of services or products.

o One thing to pay attention to is that you do not need to insert the “item #” value from input.csv but you need to rely on the DBMS to auto-generate this field for you

- Now that we got the table populated, you need to go back to index.php and change your php code to read input from the database by querying it using a select statement

- The select statement needs to query the table created using the filtering input the user enters

o Select records from the table we are working with, where the name of the item is similar to <value entered by the user>


Dataset You can download form here


Hint and reference code

<!DOCTYPE html>
<html lang="en">
<?php include ('init.php') ; ?>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
    <form action="index.php" method="post" enctype="multipart/form-data">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="style.css">

</head>	
	

<body onload="pageLoadingTime()">

<?php

class Item {	

	public $itemNumber;

	public $name;

	public $type;

	public $make;

	public $model;

	public $brand;

	public $description;	



	function __construct($itemNumber, $name, $type, $make, $model, $brand, $description){

		$this->itemNumber = $itemNumber;

		$this->name = $name;

		$this->type = $type;

		$this->make = $make;

		$this->model = $model;

		$this->brand = $brand;

		$this->description = $description;

	}
	

	function display(){
	return "Item Number : ".$this->itemNumber."<br>Item Name : ".$this->name."<br>Item Type : ".$this->type."<br>Make : ".$this->make."<br>Model : ".$this->model."<br>Brand : ".$this->brand."<br>Description: ".$this->description."<br>";
	}

}

$inFile = fopen("input.csv","r") or die("File cannot be opened!!");

$line = " ";

$line_number = 1;

$content_of_line;

$items;

$i=0;

while(!feof($inFile)){ 


$line = fgets($inFile);
if (empty($line))  {
	continue;
}
$words = explode(",",$line);

 if (!is_numeric($words[0])) {
	 continue;


$stmt = $conn->prepare("INSERT INTO items (name, type, brand, model, make, description) values (?,?,?,?,?,?);");
$stmt->bind_param("ssssss", $words[1],$words[2],$words[3],$words[4],$words[5],$words[6])
$stmt->execute();


}



fclose($inFile);

?>

    <header>
        <div class="navbar">
            <a class="active" href="#"><i class="fa fa-fw fa-home"></i> Home</a>

            <div class="dropdown">
                <button class="dropbtn">Products
                    <i class="fa fa-caret-down"></i>
                </button>
                <div class="dropdown-content">
                    <a href="currency.php">Currency Exchange</a>
                    <a href="">Service 2</a>
                </div>
            </div>

            <div class="dropdown">

                <button onclick="location.href='contact.html'" class="dropbtn">Contact Us
                    <i class="fa fa-caret-down"></i>
                </button>
                <div class="dropdown-content">

                    <a href=""><img class="countryFlag" src="img/france.png" alt="france">Contactez-nous</a>
                    <a href=""><img class="countryFlag" src="img/ukraine.png" alt="ukraine">Зв'затися з нами</a>
                </div>
            </div>

            <a href="aboutme.html">About</a>
        </div>
    </header>

    <div class="container">

        <p class="pageLoading"></p>

        <p class="bookHeader">PLASTIC SURGERY PROCEDURES</p>

        <div class="about_product">
            <h2>
                Find most needed plastic surgery procedures. 
            </h2>
        </div>

        <p class="searchText">SEARCH FOR A PROCEDURE</p>

        <div class="procedureSearch">
            <input type="text" id="searchInput" onkeyup='search(<?php echo json_encode($items) ?>)' placeholder="Search for procedure..">
        </div>

        <ul id="myUL">
            <li style="display: none;"><a href="#">A Journey to the Center of the Earth</a></li>
            <li style="display: none;"><a href="#">The War of the Worlds</a></li>
            <li style="display: none;"><a href="#">Brave New World</a></li>
            <li style="display: none;"><a href="#">When Worlds Collide</a></li>
            <li style="display: none;"><a href="#">Odd John</a></li>
            <li style="display: none;"><a href="#">Nineteen Eighty-Four</a></li>
            <li style="display: none;"><a href="#">Earth Abides</a></li>
            <li style="display: none;"><a href="#">Foundation</a></li>
            <li style="display: none;"><a href="#">The Illustrated Man</a></li>
            <li style="display: none;"><a href="#">The Demolished Man</a></li>

            <li style="display: none;"><a href="#">Ring Around the Sun</a></li>
            <li style="display: none;"><a href="#">Mission of Gravity</a></li>
            <li style="display: none;"><a href="#">The Long Tomorrow</a></li>
            <li style="display: none;"><a href="#">The Chrysalids</a></li>
            <li style="display: none;"><a href="#">The Death of Grass or No Blade of Grass</a></li>
            <li style="display: none;"><a href="#">Starship Troopers</a></li>
            <li style="display: none;"><a href="#">The Sirens of Titan</a></li>
            <li style="display: none;"><a href="#">Alas, Babylon</a></li>
            <li style="display: none;"><a href="#">A Canticle for Leibowitz</a></li>
            <li style="display: none;"><a href="#">Venus Plus X</a></li>

            <li style="display: none;"><a href="#">Solaris</a></li>
            <li style="display: none;"><a href="#">The Drowned World</a></li>
            <li style="display: none;"><a href="#">Hothouse</a></li>
            <li style="display: none;"><a href="#">A Wrinkle in Time</a></li>
            <li style="display: none;"><a href="#">Dune</a></li>
            <li style="display: none;"><a href="#">Make Room! Make Room!</a></li>
            <li style="display: none;"><a href="#">Logan's Run</a></li>
            <li style="display: none;"><a href="#">Do Androids Dream of Electric Sheep?</a></li>
            <li style="display: none;"><a href="#">The Left Hand of Darkness</a></li>
            <li style="display: none;"><a href="#">Behold the Man</a></li>

            <li style="display: none;"><a href="#">Ringworld</a></li>
            <li style="display: none;"><a href="#">Rendezvous with Rama</a></li>
            <li style="display: none;"><a href="#">Roadside Picnic / Tale of the Troika</a></li>
            <li style="display: none;"><a href="#">The Female Man</a></li>
            <li style="display: none;"><a href="#">Man Plus</a></li>
            <li style="display: none;"><a href="#">The Stand</a></li>
            <li style="display: none;"><a href="#">The Hitchhiker's Guide to the Galaxy</a></li>
            <li style="display: none;"><a href="#">Nor Crystal Tears</a></li>
            <li style="display: none;"><a href="#">Ender's Game</a></li>
            <li style="display: none;"><a href="#">Consider Phlebas</a></li>

            <li style="display: none;"><a href="#">Falling Free</a></li>
            <li style="display: none;"><a href="#">Hyperion</a></li>
            <li style="display: none;"><a href="#">Red Mars</a></li>
            <li style="display: none;"><a href="#">Ribofunk</a></li>
            <li style="display: none;"><a href="#">Cryptonomicon</a></li>
            <li style="display: none;"><a href="#">Uglies</a></li>
            <li style="display: none;"><a href="#">Old Man's War</a></li>
            <li style="display: none;"><a href="#">Little Brother</a></li>
            <li style="display: none;"><a href="#">Acme Novelty Library #19</a></li>
            <li style="display: none;"><a href="#">Embassytown</a></li>
        </ul>
			
		<div id="resultsContainer">
		</div>
</div>
		
<script src="function.js"></script>

</body>

</html>


If you need any programming assignment help in PHP programming, PHP project or PHP homework or need solution of above problem then we are ready to help you.


Send your request at realcode4you@gmail.com and get instant help with an affordable price.

We are always focus to delivered unique or without plagiarism code which is written by our highly educated professional which provide well structured code within your given time frame.


If you are looking other programming language help like C, C++, Java, Python, PHP, Asp.Net, NodeJs, ReactJs, etc. with the different types of databases like MySQL, MongoDB, SQL Server, Oracle, etc. then also contact us.


29 views0 comments

Recent Posts

See All