这是我打印出来的东西的脚本,所以我可以列出一个列表:
output.php =这应该从数据库中获取“Name”列,并使用“Name”列回显一个表。然后它将尝试使用filename.php过滤'Name'行。
<?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();
?>
不要喝酒/吸烟并尝试编码!
答案 0 :(得分:0)
我在这里做错了什么
几乎所有事情。
$row["Price"];
,因此不存在Price
这样的事情。$pics
始终为空,因此每次迭代都会显示空行。为什么$pics
总是空的?因为
$pics = seo ($name); // $name is blank, because of bullet 1.
答案 1 :(得分:0)
您没有从查询中选择“价格”..