简体   繁体   English

试图将表格放在查询结果的周围吗?

[英]Trying to put table around results from query?

I can't put a table around my results from my code and need some help as I've tried but it comes back with "Parse error: syntax error, unexpected '<' in C:\\xampp\\htdocs\\search_go.php on line 27". 我无法在代码中放一张表格,尝试时需要一些帮助,但返回时出现“解析错误:语法错误,C:\\ xampp \\ htdocs \\ search_go.php中出现意外的<<”第27行”。 So could I get help with how to insert a table? 那我可以寻求有关如何插入表格的帮助吗?

<?php

//capture search term and remove spaces at its both ends if the is any
$searchTerm = trim($_GET['keyname']);

//check whether the name parsed is empty
if($searchTerm == "")
    {
    echo "Enter name you are searching for.";
    exit();
}

//database connection info
$host = "localhost"; //server
$db = "calendar"; //database name
$user = "root"; //dabases user name
$pwd = ""; //password

//connecting to server and creating link to database
$link = mysqli_connect($host, $user, $pwd, $db);

//MYSQL search statement
$query = "SELECT * FROM caltbl WHERE evtDate LIKE '%$searchTerm%'";

$results = mysqli_query($link, $query);

<table>
/* check whether there were matching records in the table
by counting the number of results returned */
if(mysqli_num_rows($results) >= 1)
{
    $output = "";
    while($row = mysqli_fetch_array($results))
    {
        <tr>
        $output .= "date: " . $row['evtDate'] . "<br />";
        $output .= "Name: " . $row['patient'] . "<br />";
        $output .= "Course: " . $row['patientId'] . "<br />";

    }
    echo $output;
}
else
    echo "There was no matching record for the name " . $searchTerm;
?>

You can't just insert a HTML tag inside PHP code: 您不能只在HTML代码中插入HTML标记:

You can however just use an echo to send it out directly: 但是,您可以使用echo直接将其发送出去:

echo "<table>";

while($row = mysqli_fetch_array($results))
{
    $output = "<tr>";
    // <tr> This is the problem line.
    $output .= "<tr>";

    $output .= "<td>date: " . $row['evtDate'] . "<br /></td>";
    $output .= "<td>Name: " . $row['patient'] . "<br /></td>";
    $output .= "<td>Course: " . $row['patientId'] . "<br /></td>";
    $output .= "</tr>";
    echo $output;
}

Additionally you didn't close your <tr> . 另外,您没有关闭<tr> I added some extra snippets to make each field a TD in the table and then closed the row. 我添加了一些额外的代码片段,使每个字段都成为表中的TD,然后关闭该行。

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

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