无法设置样式 PHP echo
Can't style PHP echo
我无法在 PHP 中使用 css 设置回显样式。无论我做什么,它都不起作用。
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 >
$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 class php 不起作用。回声是黑色的,时代新罗马文本。我该如何解决这个问题?
您没有回应 div.php 块中的任何内容。 $output
从未在您的代码中定义。您在 div.php 块之前回显了很多次。
在我看来,您想定义或附加 $output
而不是 echo 在各个部分,例如:
echo "No results";
或者只需将 <div class="php">
放在 PHP 块之前,这样回声就会在其中。
我无法在 PHP 中使用 css 设置回显样式。无论我做什么,它都不起作用。 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 >
$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 class php 不起作用。回声是黑色的,时代新罗马文本。我该如何解决这个问题?
您没有回应 div.php 块中的任何内容。 $output
从未在您的代码中定义。您在 div.php 块之前回显了很多次。
在我看来,您想定义或附加 $output
而不是 echo 在各个部分,例如:
echo "No results";
或者只需将 <div class="php">
放在 PHP 块之前,这样回声就会在其中。