使用HTML的PHP​​表 [英] PHP Table using HTML

查看:40
本文介绍了使用HTML的PHP​​表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是使用txt文件,该文件具有填写表单后进行特定回复所需的数据.该表格应该具有用户名和密码.另外,在表格上可以设置一个价格范围参数.用户名可以在任何情况下写,但是密码区分大小写.我已经创建了将要使用的html表单.txt文件中的数据包含商品的地址和商品价格.价格范围参数可以设置为任何值,目标是仅将txt文件中的数据作为生成的响应返回,以完成表单.我创建的表单是

My goal is to use a txt file which has the data needed for a specific response from filling out a form. 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. The data on the txt file contains addresses’ for listings and the listings price. 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. 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>

唯一有效的用户名是

用户名:joe [any case(jOE)]

Username: joe [any case(jOE)]

密码:老虎[区分大小写]

Password: tiger [case sensitive]

当我创建响应文件时,应该使用php语法还是html并将php编码插入html文档中.我正在使用sublime,这就是为什么我问要使用哪种语法.表单返回页面时,必须将信息放置在两列的表中.我还没有开始编写响应页面代码,我希望获得有关如何构造所需代码的帮助.必须返回的文本文件是这个.

When I create the response file, should I use php syntax or use html and insert the php coding within the html document. I am using sublime, that is why I ask which syntax to use. 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;

注意:•正确的用户名是joe,正确的密码是Tiger.可以在任何情况下键入用户名,并且用户名后可以有前导或尾随空格.但是,密码必须用小写字母键入,密码后面不能有前导和尾随空格.

Notes: • The correct username is joe and the correct password is 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.

•如果用户没有输入正确的用户名和密码,他或她将收到一个带有h3标题的网页,其中包含一条消息,内容为无效的用户名或密码".

• 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."

•如果用户输入正确的用户名和密码,他或她将收到一个带有表格的网页,该表格列出了所有在指定价格之间的房屋.(之间的含义是大于或等于较低的数字,小于或等于较高的数字.)在此网页的末尾将显示该表格的副本,以便用户可以键入另一个请求.

• 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.

•PHP输出的格式应如示例所示.单词这里是所有价格在$ 100000到$ 500000之间的房子"应该在表格的h3标题中(并且美元符号应印在所示数字的前面).表格的边框应为2px的红色实心边框,如图所示.标题再试一次"应为h3标题.

• The PHP output should be formatted as shown in the example. 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). The borders of the table should be 2px solid red borders as shown. The heading "Try Again" should be an h3 heading.

<?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).

然后,您需要放入一些PHP逻辑以显示数据(如果有的话)或无效登录的错误.

Then you would need to put in some PHP logic to show data if there is any, or the error for invalid login.

要显示房屋,可以包含文本文件,然后遍历数组并查找所需范围内的任何内容.您可以使用foreach循环.

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.

<!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> ...

这篇关于使用HTML的PHP​​表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆