PHP输出脚本只输入'row'而不是mysql行


PHP output script just putting 'row' instead of mysql rows?

这是我打印东西的脚本,这样我就可以做一个列表了:

output.php =这应该从数据库中获取'Name'列,并回显包含'Name'列的表。然后,它将尝试过滤'Name'行with 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();
?>

My filename2.php:这应该需要seo function并将行转换为我可以输出的东西。我感觉问题就在这里?

<?php
    require_once ('seo.php');
    $name= $row["Price"];
    $pics = seo ($name);
?>

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

不喝酒、不抽烟、不编程

我哪里做错了

几乎一切。

  1. 没有$row["Price"];这样的东西,因为你没有选择Price
  2. 那个奇怪的包含电话是怎么回事?每次迭代都会重复。
  3. $pics始终为空,因此每次迭代都得到空白行。

为什么$pics总是空的?因为

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

您没有从查询中选择'Price' .