简体   繁体   English

我有一个搜索结果页面,但我不知道如何混合php和html !? 怎么样?

[英]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.

相关问题 PHP:我得到一个完全空白的页面,我不知道如何在PHP中调试它 - PHP: I get a completely blank page, I don't know how to debug this in PHP 我在 PHP 中制作了一个代理刮板,但我不知道如何检查代理是否处于活动状态 - I have made a proxy scraper in PHP but I don't know how to check if the proxy is live 如果我不知道基本 DN 的 OU,如何通过 PHP ldap_search() 获取用户 OU - How to PHP ldap_search() to get user OU if I don't know the OU for base DN 我想在 php 中做 if else 但我不知道怎么做 - I want to make if else in php but i don't know how 如何使用PHP和HTML绘制这种类型的“二进制矩阵”图形(老实说,我不知道它是否有名称) - How to plot this type of “binary matrix” graphic (I honestly don't know if it has a name) using PHP and HTML 我不知道如何将数组变量从 jquery 传递到其他 php 页面 - I don't know how to passing array variabel from jquery to other php page 如何混合使用PHP和HTML代码? - How can I mix PHP and HTML code? 我不知道如何创建 sql 查询 api php? - I don't know how to create sql query api php? 我不知道如何在php中获取序列化数据 - I don't know how to fetch serialized data in php 在我的 SuiteeCRM 主页中,我有很多警告,如下所示,我不知道如何摆脱它们 - In my home page of SuiteeCRM, i have a lot of warnings as its written below, i don't know how to get rid of them
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM