简体   繁体   English

使用 HTML 的 PHP 表格

[英]PHP Table using HTML

My goal is to use a txt file which has the data needed for a specific response from filling out a form.我的目标是使用一个 txt 文件,其中包含填写表单的特定响应所需的数据。 The form is supposed to have a username and password.该表单应该有一个用户名和密码。 Also, there is to be a price range parameters that can be set on the form.此外,还有一个可以在表格上设置的价格范围参数。 The username can be written in any case however the password is case sensitive.用户名可以在任何情况下写入,但密码区分大小写。 I have created the html form that I will be using.我已经创建了我将使用的 html 表单。 The data on the txt file contains addresses' for listings and the listings price. txt 文件中的数据包含列表的地址和列表价格。 The price range parameters can be set to any values, the goal is to just return the data from the txt file as a generated response for completion of the form.价格范围参数可以设置为任何值,目标是将 txt 文件中的数据作为完成表单的生成响应返回。 The form I have created is,我创建的表格是,

<!DOCTYPE html>

<html>
<head>
<title></title>
</head>
<body>
<form action="houseprices.txt"
      method="post">
Show houses whose price is between:
<input name="lowprice" type="text" size="15" maxlength="15" /> & 
<input name="highprice" type="text" size="15" maxlength="15" /><br />
Username:   <input name="user" type="text" size="15" maxlength="15" /><br />
Password:   <input name="pw" type="password" size="15" maxlength="15" /><br />
<input type="submit" value="Show Houses" />
</form>
</body>
</html>

The only valid username is to be唯一有效的用户名是

Username: joe [any case(jOE)]用户名:joe [任何情况(joE)]

Password: tiger [case sensitive]密码:tiger [区分大小写]

When I create the response file, should I use php syntax or use html and insert the php coding within the html document.当我创建响应文件时,我应该使用 php 语法还是使用 html 并在 html 文档中插入 php 编码。 I am using sublime, that is why I ask which syntax to use.我正在使用 sublime,这就是为什么我问使用哪种语法。 The information must be placed in a two column table when the form returns a page.当表单返回页面时,信息必须放在一个两列的表格中。 I have yet to begin writing the response pages code I was hoping to get some help with how I should structure the desired code.The text file that must be returned is this.我还没有开始编写响应页面代码,我希望在如何构建所需代码方面得到一些帮助。必须返回的文本文件是这个。

$houseprices["123 Elm"]=260000;
$houseprices["96 Otis"]=340000;
$houseprices["9 Windham Place"]=560000;
$houseprices["293 Wilma"]=230000;
$houseprices["6789 Beach"]=800000;
$houseprices["535 Overlook"]=750000;
$houseprices["59 South Lake"]=900000;
$houseprices["19 Ash"]=270000;
$houseprices["6820 Butternut"]=340000;
$houseprices["902 Weston"]=190000;
$houseprices["496 Ervin"]=340000;
$houseprices["316 Pond"]=280000;
$houseprices["7282 Main"]=420000;
$houseprices["561 Billings"]=350000;
$houseprices["117 Peach"]=280000;
$houseprices["2171 Bentley"]=300000;
$houseprices["365 Prescott"]=1120000;
$houseprices["319 Paley"]=310000;
$houseprices["43 Maple"]=150000;
$houseprices["291 Wilson"]=320000;
$houseprices["81 Essex"]=330000;
$houseprices["995 West Lawrence"]=480000;
$houseprices["679 Esther"]=240000;
$houseprices["6890 Patten"]=600000;
$houseprices["53 Lower Pond"]=250000;
$houseprices["4567 Washington"]=170000;
$houseprices["691 Holt"]=1900000;
$houseprices["1234 Main"]=180000;
$houseprices["6 Cherry"]=360000;
$houseprices["639 Perrywinkle"]=190000;
$houseprices["86 Foster"]=1300000;
$houseprices["341 Elm   "]=200000;
$houseprices["5122 Bern"]=350000;
$houseprices["688 Maple"]=210000;
$houseprices["64 Oak"]=640000;
$houseprices["874 Marlin"]=220000;
$houseprices["53 Lake"]=190000;
$houseprices["206 Alban"]=310000;
$houseprices["371 Martha"]=420000;
$houseprices["866 Delaware"]=230000;
$houseprices["342 West Lawrence"]=440000;
$houseprices["63 Ashley"]=450000;
$houseprices["49 Tabler"]=260000;
$houseprices["417 Deermill"]=370000;
$houseprices["38 Holt"]=490000;
$houseprices["689 Aspen"]=300000;
$houseprices["4441 Park"]=210000;
$houseprices["8394 North Lake"]=320000;
$houseprices["722 Perry"]=530000;
$houseprices["99 East Ridge"]=260000;
$houseprices["4374 Elderberry"]=270000;
$houseprices["89 Lubbock"]=370000;
$houseprices["12543 Benson"]=380000;
$houseprices["240 London"]=290000;
$houseprices["745 Park"]=390000;
$houseprices["18 Wilson"]=400000;
$houseprices["11 Westgate"]=540000;
$houseprices["4736 East River"]=250000;
$houseprices["4793 Chauncey Circle"]=370000;
$houseprices["3073 West Main"]=280000;

Notes: • The correct username is joe and the correct password is tiger.注意: • 正确的用户名是joe,正确的密码是tiger。 The username may be typed in any case and may have leading or trailing spaces after it.在任何情况下都可以输入用户名,并且在其后可以有前导或尾随空格。 However, the password must be typed all lower case with no leading and trailing spaces after it.但是,密码必须全部小写,后面没有前导和尾随空格。

• If the user does not type in the correct username and password he or she will receive a webpage with an h3 heading containing a message saying, “Invalid Username or Password.” • 如果用户没有输入正确的用户名和密码,他或她将收到一个带有 h3 标题的网页,其中包含一条消息,内容为“用户名或密码无效”。

• If the user does type the correct username and password he or she will receive a webpage with a table listing all of the houses that are between the prices specified. • 如果用户确实输入了正确的用户名和密码,他或她将收到一个网页,其中列出了指定价格之间的所有房屋。 (Between means greater than or equal to the lower number and less than or equal the higher number.) At the end of this webpage will be a copy of the form so that user can type in another request. (介于表示大于或等于较低的数字和小于或等于较高的数字。)在此网页的末尾将是表格的副本,以便用户可以输入另一个请求。

• The PHP output should be formatted as shown in the example. • PHP 输出的格式应如示例中所示。 The words, “Here are all the houses whose prices are between $100000 and $500000” should be in an h3 heading inside the of the table (and the dollar signs should be printed before the numbers as shown). “这是价格在 100000 美元到 500000 美元之间的所有房子”这句话应该放在表格内的 h3 标题中(并且美元符号应该打印在数字之前,如图所示)。 The borders of the table should be 2px solid red borders as shown.如图所示,表格的边框应为 2px 实心红色边框。 The heading “Try Again” should be an h3 heading.标题“再试一次”应该是一个 h3 标题。

<?php
echo "<!DOCTYPE html>";
echo "<html>";
echo "<head>";
echo "<title>Houses</title>";
echo "</head>";
echo "<body>";
echo '<h3> Here are all the houses whose prices are between $100000 and $500000: </h3>';


echo "</body>";
echo "</html>";
?>

I'd start by posting your form to the same page as the form (so you can resuse the form).我首先将您的表单发布到与表单相同的页面(以便您可以重复使用该表单)。

Then you would need to put in some PHP logic to show data if there is any, or the error for invalid login.然后,您需要放入一些 PHP 逻辑来显示数据(如果有)或无效登录的错误。

To show the houses, you can include the text file and then run through your array and look for anything in the range you want.要显示房屋,您可以包含文本文件,然后遍历数组并查找所需范围内的任何内容。 You could use a foreach loop.您可以使用 foreach 循环。

<!DOCTYPE html>
<html>
<head>
  <title>Your Form Page</title>
</head>
<body>
<!-- Your HTML STUFF BEFORE WHERE YOU WANT THE TABLE TO BE -->


<?php  // This tag opens up PHP
//Check to see if username & password are correct
if(strcmp($_POST['username]'], 'joe') === 0 && strcasecmp($_POST['password'], 'tiger') === 0) {

  // Include the array from your text file -- as you've structured it as PHP
  require('textfile.txt');

  // Start the table
  echo '<table><tr><th>Address</th><th>Price</th></tr>';

  foreach($houseprices as $address => $price) {
    if($price >= $_POST['lowprice'] && $price <= $_POST['highprice']){
      echo '<tr><td>' . $address . '</td><td>$' . $price . '</td></tr>';
    }
  }

  // Close out the table
  echo '</table>';

} else {
  // Display warning about password/username
  echo '<h2>Incorrect Username or Password</h2>';
}

// The tag below will close php
?>

<!-- The rest of your HTML goes down here -->
<form> ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM