duanke3985 2015-07-13 07:29
浏览 39
已采纳

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

This is my script for printing out stuff so I can make a list:

output.php = This is supposed to fetch the 'Name' column from the database and echo a table with the column 'Name'. Then it will try to filter the 'Name' Row with 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: This is supposed to require the seo function and translate rows into something I can output. I have a feeling the issue is here?

<?php

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

?>

My seo.php:This removes all of the spaces and bad characters and optimizes their name:

<?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, '-'));
}

?>

The out put is just

Row

Row

Row

Row

Nothing else. What am I doing wrong here?


Fixed the code after a little bit of not being stupid:

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

Don't drink/smoke and try to code !

  • 写回答

2条回答 默认 最新

  • doushi1847 2015-07-13 07:38
    关注

    What am I doing wrong here

    Almost everything.

    1. There is no such thing as $row["Price"]; since you don't SELECT Price.
    2. What's up with that weird include call? Will be repeated for each iteration.
    3. $pics is always empty, hence you get blank rows for each iteration.

    Why is $pics always empty? Because

    $pics = seo ($name); // $name is blank, because of bullet 1.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c