- PHP 7 Programming Blueprints
- Jose Palala Martin Helmich
- 284字
- 2021-07-08 11:14:10
Creating views
Now that we have our model complete, a template render function, we just need to create the view with which we can look at each profile.
Our view will be put inside a foreach
block, and we'll use the template we wrote to render the right values:
//listprofiles.php <html> <!doctype html> <head> <link rel="stylesheet" > </head> <body> <?php foreach($results as $item) { echo profile_template($item->name, $item->age, $item->country; } ?> </body> </html>
Let's put the code above into index.php
.
While we may install the Apache server, configure it to run PHP, install new virtual hosts and the other necessary features, and put our PHP code into an Apache folder, this will take time. So, for the purposes of testing this out, we can just run PHP's server for development.
To run the built-in PHP server (read more at http://php.net/manual/en/features.commandline.webserver.php ) we will use the folder we are running, inside a terminal:
php -S localhost:8000
If we open up our browser, we should see nothing yet, No results found. This means we need to populate our database.
If you have an error with your database connection, be sure to replace the correct database credentials we supplied into each of the mysql_connect
calls that we made.
- To supply data to our database, we can create a simple SQL script like this:
INSERT INTO user_profiles ('Chin Wu', 30, 'Mongolia'); INSERT INTO user_profiles ('Erik Schmidt', 22, 'Germany'); INSERT INTO user_profiles ('Rashma Naru', 33, 'India');
- Let's save it in a file such as
insert_profiles.sql
. In the same directory as the SQL file, log on to the MySQL client by using the following command:mysql -u root -p
- Then type use <name of database>:
mysql> use <database>;
- Import the script by running the source command:
mysql> source insert_profiles.sql
Now our user profiles page should show the following:

- ClickHouse性能之巔:從架構設計解讀性能之謎
- Facebook Application Development with Graph API Cookbook
- Java異步編程實戰
- Visual Studio 2012 Cookbook
- 零起步玩轉掌控板與Mind+
- 信息可視化的藝術:信息可視化在英國
- Java性能權威指南(第2版)
- Oracle BAM 11gR1 Handbook
- Java設計模式及實踐
- C程序設計案例教程
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(高級進階篇)
- Mastering Xamarin.Forms(Second Edition)
- Cocos2d-x Game Development Blueprints
- 編程改變生活:用Python提升你的能力(進階篇·微課視頻版)
- 邊玩邊學Scratch3.0少兒趣味編程