This is a simple PHP application that demonstrates a product catalog with search functionality and pagination.
- Product Storage: Products are stored in a PHP array with details like name, description, price, and category.
- Search Functionality: Users can search for products by name, description, or category using the search bar.
- Dynamic Results Display: Search results are displayed dynamically based on user input.
- Pagination: For better user experience, results are paginated (5 items per page).
- The application uses a PHP array to store product information.
- When a user submits a search query via GET request, the application filters the products array.
- The filtered results are then paginated using PHP's array functions.
- The front-end uses HTML and CSS for presentation with a responsive grid layout.
- Arrays: Product data is stored and manipulated using PHP arrays.
- Forms: A search form is used to capture user input.
- GET Requests: Search parameters are passed via URL query parameters.
- Pagination: Custom pagination implementation to handle large datasets.
- Place the
index.phpfile in your web server directory. - Start your web server (Apache, Nginx, etc.).
- Access the application through your browser (e.g.,
http://localhost/index.php).
index.php: Main application file containing all functionality.README.md: This documentation file.
The search feature uses PHP's array_filter() function to filter products based on the search term. The search checks the product name, description, and category using case-insensitive matching.
Pagination is implemented by:
- Calculating the total number of items and pages
- Determining the current page from the URL parameter
- Using
array_slice()to extract only the items for the current page
The application uses htmlspecialchars() to prevent XSS attacks when displaying user input and search results.
You can customize the application by:
- Adding more products to the
$productsarray - Modifying the styling in the CSS section
- Changing the number of items per page by modifying the
$itemsPerPagevariable