【发布时间】:2015-07-13 07:29:37
【问题描述】:
这是我打印东西的脚本,所以我可以列个清单:
output.php = 这应该从数据库中获取“名称”列并回显包含“名称”列的表。然后它将尝试使用 filename.php 过滤“名称”行。
<?php
include 'go.php';
$sql = "SELECT Name FROM utf";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<div class=\"CSSTableGenerator style=\"width:600px;height:150px;\"><table><tr><th>Name</th></tr></div>";
// output data of each row
while($row = $result->fetch_assoc()) {
include 'filename2.php';
echo "<tr><td>".$pics."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
我的 filename2.php:这应该需要 seo function 并将行转换为我可以输出的内容。我感觉问题出在这里?
<?php
require_once ('seo.php');
$name= $row["Price"];
$pics = seo ($name);
?>
我的 seo.php:这会删除所有的空格和坏字符并优化它们的名称:
<?php
function seo($string){
$string = str_replace(array('[\', \']'), '', $string);
$string = preg_replace('/\[.*\]/U', '', $string);
$string = preg_replace('/&(amp;)?#?[a-z0-9]+;/i', '-', $string);
$string = htmlentities($string, ENT_COMPAT, 'utf-8');
$string = preg_replace('/&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '\\1', $string );
$string = preg_replace(array('/[^a-z0-9]/i', '/[-]+/') , '-', $string);
return strtolower(trim($string, '-'));
}
?>
输出只是
行
行
行
行
没有别的了。我在这里做错了什么?
在一点不傻之后修复了代码:
<?php
include 'go.php';
include 'seo.php';
$sql = "SELECT Name FROM utf";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<div class=\"CSSTableGenerator style=\"width:600px;height:150px;\"><table><tr><th>Name</th></tr></div>";
// output data of each row
while($row = $result->fetch_assoc()) {
$name = ('$row["Name"]');
$seo2 = seo ($row["Name"]);
$ext = '.jpg';
$pics = $seo2 . $ext ;
echo "<tr><td>".$pics."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$conn->close();
?>
不要喝酒/吸烟并尝试编码!
【问题讨论】:
-
我不明白 - 如果您只选择名称,为什么要从结果中获取价格?
-
您在循环中回显
$pics,而不是$row,您在期待什么? -
先尝试统一这些文件。在具有
require_once的脚本上使用include也是没有意义的。尝试将文件转换为output.php 中的函数。