PHP输出脚本只是放'行'而不是mysql行?

时间:2015-07-13 07:29:37

标签: php mysql

这是我打印出来的东西的脚本,所以我可以列出一个列表:

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();
?>

不要喝酒/吸烟并尝试编码!

2 个答案:

答案 0 :(得分:0)

  

我在这里做错了什么

几乎所有事情。

  1. 由于您没有选择$row["Price"];,因此不存在Price这样的事情。
  2. 奇怪的包括电话是什么?每次迭代都会重复。
  3. $pics始终为空,因此每次迭代都会显示空行。
  4. 为什么$pics总是空的?因为

    $pics = seo ($name); // $name is blank, because of bullet 1.
    

答案 1 :(得分:0)

您没有从查询中选择“价格”..