[英]I have a search results page but I don't know how to mix php and html!? How?
I have a search results page and I want to display it in tables. 我有一个搜索结果页面,我想在表格中显示它。 how do I do so? 我该怎么办? I am completely unsure of how to mix php together with html. 我完全不确定如何将php与html混合使用。
My code is: 我的代码是:
<?php
if(strlen(trim($_POST['search'])) > 0) {
$search = "%" . $_POST["search"] . "%";
$searchterm = "%" . $_POST["searchterm"] . "%";
mysql_connect ("", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
}
$query = "SELECT name,location,msg FROM contact WHERE name LIKE '%$search%' AND
location LIKE '%$searchterm%'";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) {
<center>
<table height="20" width="990" cellpadding="0" cellspacing="0">
<tr>
<td>
<table height="20" width="215" cellpadding="0" cellspacing="0">
<tr>
<td>
<font face="lucidagrande" size="4" color="#045FB4">$row[0]</font>
</td>
</tr>
</table>
</td>
<td>
<table height="20" width="775" cellpadding="0" cellspacing="0">
<tr>
<td>
<font face="lucidagrande" size="4" color="black">$row[1]</font>
<td align="right">
<font face="lucidagrande" size="2" color="red">See More...</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
}
}
}
?>
Thanks! 谢谢!
James 詹姆士
PHP parsing is based on the existence of two tags: PHP解析基于两个标签的存在:
<?php
?>
Anything inside the PHP "xml" tags is to be PHP code. PHP“ xml”标签内的所有内容均应为PHP代码。 Anything outside is to be normal HTML. 外面的任何东西都是普通的HTML。 So: 所以:
<p><?php echo 'Hello, world!'; ?></p>
Means to output the <p></p>
normally, but let the PHp parser handle the echo 'Hello, world!';
意味着通常输出<p></p>
,但是让PHp解析器处理echo 'Hello, world!';
So, changes are that after your while(...){
statement you want a ?>
(to end PHP code and begin outputting the <center>
tag and tables.) Then, towards the bottom, you'll need a <?php
before the braces ( }
). 因此,变化是在while(...){
语句之后,您想要一个?>
(结束PHP代码并开始输出<center>
标记和表。)然后,在底部,您需要一个<?php
括号前的<?php
( }
)。
Finally, every time you see a variable like $row[0]
you'll need to surround it with php tags. 最后,每次您看到$row[0]
类的变量时,都需要用php标签将其包围。 either of these is acceptable: 以下任何一个都可以接受:
<?=$row[0];?>
<?php echo $row[0]; ?>
This is one option: 这是一个选择:
<?php
if(strlen(trim($_POST['search'])) > 0) {
$search = "%" . $_POST["search"] . "%";
$searchterm = "%" . $_POST["searchterm"] . "%";
mysql_connect ("", "", "");
mysql_select_db ("");
if (!empty($_POST["search_string"]))
{
}
$query = "SELECT name,location,msg FROM contact WHERE name LIKE '%$search%' AND
location LIKE '%$searchterm%'";
$result = mysql_query ($query);
if ($result) {
while ($row = mysql_fetch_array ($result)) { ?>
<center>
<table height="20" width="990" cellpadding="0" cellspacing="0">
<tr>
<td>
<table height="20" width="215" cellpadding="0" cellspacing="0">
<tr>
<td>
<font face="lucidagrande" size="4" color="#045FB4"><?php echo $row[0]; ?></font>
</td>
</tr>
</table>
</td>
<td>
<table height="20" width="775" cellpadding="0" cellspacing="0">
<tr>
<td>
<font face="lucidagrande" size="4" color="black"><?php echo $row[1]; ?></font>
<td align="right">
<font face="lucidagrande" size="2" color="red">See More...</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
}
}
?>
You have to end the PHP before you can start the HTML, and vice versa. 必须先结束PHP,然后才能启动HTML,反之亦然。
<?php
// PHP goes here
?>
<!-- HTML goes here -->
<?php
// More PHP here
?>
将php标签放在php代码所在的位置
<font face="lucidagrande" size="4" color="black"><?php echo $row[1]; ?></font>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.