Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Ive been having troubles with this project for a few days now. I am haing troubles with displaying the vehicles with the selected filter and displaying the images associated with them. Here is a complete list of what i have to do:

I Need To
- Find any errors in the code
- Properly include and initialize the class.
- Populate the “Filters” using the class provided as outlined in the index.php file.
- Properly post the “Filters” form.
- Populate the “Vehicle Results” using the class and the “Filters” as outlined in the index.php file.
- Layout and style your vehicle results.
- Leverage lightGallery to display larger images.

What I have tried:

This Is What I Have So Far

index.php
<pre lang="PHP"><pre><?php
include ("resources/Parser.class.php");
$Parser = new Parser('resources/warehouse.csv');

?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample Project</title>

<link rel="stylesheet" href="resources/css/layout.css" type="text/css" />

</head>

<body>

<!--open wrapper-->
<div id="wrapper" class="fixed">

	<!--open left-column-->
	<div id="left-column" class="f_left">
        
        <h2>Filters</h2>
        <hr />
        
        <form name="filters" action="" method="post">
            <select name="year" class="select">
                <option value="">-Year-</option>
                <?php

                //CREATE LIST OF YEARS, ORDER NUMERICALLY ASCENDING

                $getYear = $Parser->get_vehicle_years();
                sort($getYear);
                
                // Iterate through the product array
                foreach($getYear as $years){
                    echo "<option value='($years)'>$years</option>";
                }

                // Collect value from form using POST
                $year = $_POST['year'];

                ?>
            </select>
            <select name="make" class="select">
                <option value="">-Make-</option>
                <?php

				//CREATE LIST OF MAKES, ORDER ALPHEBETICALLY ASCENDING

                $getMake = $Parser->get_vehicle_makes();
                sort($getMake);

                // Iterate through the product array
                foreach($getMake as $makes){
                    echo "<option value='($makes)'>$makes</option>";
                }

                // Collect value from form using POST
                $make = $_POST['make'];
				
                ?>
            </select>
            <select name="model" class="select">
                <option value="$models">-Model-</option>
                <?php

				//CREATE LIST OF MODELS, ORDER ALPHEBETICALLY ASCENDING

                $getModel = $Parser->get_vehicle_models();
                sort($getModel);

                // Iterate through the product array
                foreach($getModel as $models){
                   echo "<option value='($models)'>$models</option>";
                }

                // Collect value from form using POST
                $model = $_POST['model'];
               
                ?>
            </select>
            <input type="submit" name="submit" class="submit" value="Filter ›" />
        </form>
    </div><!--close left-column-->

	<!--open right-column-->
	<div id="right-column" class="f_right">
    	
        <h2>Vehicles</h2>
        <hr />
    
        <?php

		//DISPLAY VEHILCES HERE WITH SELECTED FILTERS

        ?>
    </div><!--close right-column-->
    
</div><!--close wrapper-->

<!--scripts-->
<script src="resources/js/jquery-1.11.3.min.js"></script>

</body>
</html>


Parser.class.php

PHP
<pre><?php



class Parser{
	

	public $data_array;
	

	public function __construct($filename){	
	
		$fp = fopen($filename, "r+") or die ('File `' .$filename. '` not found.');
		$database = fread($fp, filesize($filename));
		fclose($fp);
		
		$row = explode("\r\n", $database);
		for($i=0; $i<count($row); $i++){
			$field = explode(",", $row[$i]);
			array_unshift($field, $i);
			$data_array[] = $field;
		}
		
		$this->data_array = $data_array;
    }
	

	public function get_vehicles(&$year='', &$make='', &$model=''){
		$response = array();
		foreach($this->data_array as $data){
			$success = true;
			if($year != '' && $data[1] != $year){ $success = false;  echo "ERROR"; }
			if($make != '' && $data[2] != $make){ $success = false; echo "ERROR"; }
			if($model != '' && $data[3] != $model){ $success = false; echo "ERROR";}
			if($success){
				$response[] = array(
				    'id' => $data[0], 
				    'year' => $data[1], 
				    'make' => $data[2], 
				    'model' => $data[3]);	
			}
			return $response;
		}
	}


	public function get_vehicle_id(){
		$response = array();
		foreach($this->data_array as $data){
			$response[] = $data[0];	
		}
		return array_unique($response);
	}


	public function get_vehicle_years(){
		$response = array();
		foreach($this->data_array as $data){
			$response[] = $data[1];	
		}
		return array_unique($response);
	}
	

	public function get_vehicle_makes(){
		$response = array();
		foreach($this->data_array as $data){
			$response[] = $data[2];	
		}
		return array_unique($response);
	}
	

	public function get_vehicle_models(){
		$response = array();
		foreach($this->data_array as $data){
			$response[] = $data[3];	
		}
		return array_unique($response);
	}

	
	public function get_vehicle_images($id){
		$response = array();
		for($i=4; $i<count($this->data_array[$id]); $i++){
			if($this->data_array[$id][$i] != '' && file_exists('img/'.$this->data_array[$id][$i])){
				$response[] = $this->data_array[$id][$i];	
			}
		}
		return $response;
	}
	
}
?>


warehouse.csv

PHP
1991,Alfa Romeo,164L,853d9a63-12ce-45c7-9e8f-ac1a1da15ced.jpg,,
2005,Ferrari,F1 Spider,8a39d397-d9b9-4692-b531-3e8571354614.jpg,4949659d-4f9e-4a3e-97d4-b57794ad32fb.jpg,
2007,Maserati,Quattroporte,82eb91b5-53f1-48cc-91b4-fe19ad22576d.jpg,b4a1847f-a6e8-4fa5-a3b4-e44f064fc88c.jpg,
2008,Audi,A5,9f972e54-74e4-4fdb-9366-012e91e03b5e.jpg,52c389f4-e9b4-4ec3-bb68-d48b3c06d08a.jpg,493ad6ba-7f72-44a1-b0c4-6d79744153f3.jpg
2009,Audi,TT,2d84fbdc-fb8f-462c-81ea-40bd9ecc168d.jpg,9a3c8f29-e574-4544-8eb8-86eb944e5f69.jpg,81b007ff-89c7-4fe1-b945-3f8b4ad15a7a.jpg
2009,Hummer,H3T,355f5ccc-333d-4ab3-8341-8e6441a6f179.jpg,fd344164-2e0a-47e9-8171-00f0e055f0d1.jpg,
2010,Dodge,Dakota,14eaf83d-56f6-4d96-aa80-1ec701cb7fff.jpg,d962f3f0-36ae-40dd-8567-890e9849f083.jpg,
2012,Dodge,Journey,50b13842-7fc3-4438-946b-3b9cc31e10bc.jpg,150b79ed-5cf3-4279-9e7e-271c6ea8a3d3.jpg,775d9c87-c31f-4f62-b26d-28c3fa597b39.jpg
2012,Mini,Cooper,09e1d1d4-8259-42a6-a8f9-baa2a69be9bf.jpg,866f5f85-446a-4c19-b1cc-256841c5c293.jpg,e91ad065-842a-484f-a90f-4256f7c8830a.jpg
2013,Mini,Cooper,5c1e6371-d8f8-4769-8d93-8d41c8051411.jpg,631219d1-6304-4b26-b5ba-ca465f6b1934.jpg,eb1a80a1-f448-4c6b-bd95-a942a206441d.jpg
1967,Pontiac,Firebird,2bbae7b2-c1ea-409e-b9c4-54a37e9ce062.jpg,5374d77f-5233-441b-b717-022e57e4fcb6.jpg,7543abae-2077-4676-a69f-1f6490aee034.jpg
1980,AMC,Spirit,039ed535-48e2-448b-8bb1-5c3739fb16ea.jpg,f3cb6293-5b95-46b3-95bd-c5144a19cace.jpg,
1991,Eagle,Talon,d3158a02-ef75-4664-a967-2b068f85be97.jpg,,
2003,Lamborghini,Murcielago,9e27531e-3040-4ad1-aabb-d8681594cbf2.jpg,45c82875-62cc-4b9e-be01-984cb087e8ca.jpg,94ebae9c-0b76-4d61-ae7d-f33ad5155c23.jpg
2007,BMW,X3,81e80677-1030-4671-8382-ea1a2f55ec48.jpg,b87988b9-1a15-4823-b883-d59c65f6aeef.jpg,bd77b49c-89c3-4a67-87c4-e1620ed7c6dd.jpg
2007,Sterling,360,20070201120516328_c75fc9f47ce64a9281b78a5a50a4bc9b0-orig.jpg,,
2009,Aston Martin,Vantage,0a60bd3c-04a3-48cb-af09-6fecc27c152f.jpg,52e0b69b-b000-4a4a-8f47-87900aeed9e4.jpg,038657f9-bdf2-4f03-93ec-a1a97ae37b8b.jpg
2012,Bentley,Continental,0c11fd9e-4243-478b-a418-275736b43734.jpg,3d25f96f-1761-4d99-b72c-924716c1486f.jpg,49e510d3-f546-4643-b71c-1e597a546254.jpg
2013,Jaquar,XJ,16a8fd60-1867-4c8f-b452-55b70294b909.jpg,564768a9-824f-4fb4-acd4-763147b3ed58.jpg,
2014,Lotus,Seven Westfield,2ab60193-6a9c-4663-96a7-46df85efdcc6.jpg,2c32e562-adae-4eda-8a68-09df89aec912.jpg,c303483b-eb62-49ca-8daf-5c7dddd0e005.jpg


I heard about how helpfull and willing this comunity is and I am very thankfull for any help at all.
Posted
Updated 26-Feb-21 21:41pm
Comments
Richard MacCutchan 27-Feb-21 3:50am    
If you want help then you need to ask a question. All we have here is some code and some data, but no explanation of what your problem is.

1 solution

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900