无法设置PHP回声样式

时间:2016-12-22 18:15:42

标签: php html styles echo

我无法使用css在PHP中设置回声样式。不管我做什么,它都不起作用。 php函数是一个搜索栏,它将回显来自mysql数据库的结果。 这是CSS:

.php {
font-family: montserrat, sans-serif;
font-style: normal;
font-weight: 200;
text-align: justify;
color: rgba(200,200,200,1.00);
}

PHP:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<form  method="GET" action="index.php"  id="searchform"> 
<input  type="text" name="query" placeholder="Enter keyword..."> 
<input  style="width:30%;height:24px;" type="submit" name="submit" value="Search">
</form>
<?php

$hostname = "localhost";
$username = "user123";
$password = "pass123";

mysql_connect($hostname, $username, $password);
mysql_select_db("tehdatabase") or die(mysql_error());

$query = $_GET['query']; 
// gets value sent over search form

$min_length = 1;
// you can set minimum length of the query if you want

if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then

    $query = htmlspecialchars($query); 
    // changes characters used in html to their equivalents, for example: < to &gt;

    $query = mysql_real_escape_string($query);
    // makes sure nobody uses SQL injection

    $raw_results = mysql_query("SELECT * FROM env
        WHERE (`id` LIKE '%".$query."%') OR (`name` LIKE '%".$query."%') OR (`short` LIKE '%".$query."%') OR (`short_withtag` LIKE '%".$query."%')") or die(mysql_error());

    // * means that it selects all fields, you can also write: `id`, `title`, `text`
    // articles is the name of our table

    // '%$query%' is what we're looking for, % means anything, for example if $query is Hello
    // it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
    // or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'

    if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following

        while($results = mysql_fetch_array($raw_results)){
        // $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop

            echo "<p><h3>".$results['id']."</h3>".$results['name'].$results['short'].$results['short_withtag']."</p>";
            // posts results gotten from database(title and text) you can also show id ($results['id'])
        }

    }
    else{ // if there is no matching rows do following
        echo "No results";
    }

}
else{ // if query length is less than minimum
    echo "Please enter at least one character";
}
?>
<div class="php">
<?php
echo("$output");
?>
</div>
</body>
</html>

我在互联网上找到了这个,除了一件事,它完美无缺。 应该为输出设置样式的div类php不起作用。回声是黑色的,是新罗马文本的时代。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

你没有在div.php块中回显任何东西。 $output永远不会在您的代码中定义。你在div.php块之前回复了很多次。

在我看来,您希望在以下各个部分中定义或追加$output而不是回声:

echo "No results";

或者只是将<div class="php">放在PHP块之前,这样回声就会在其中。