【问题标题】:PHP get results from mysql DB with href links and labelPHP从带有href链接和标签的mysql DB获取结果
【发布时间】:2020-03-05 07:22:10
【问题描述】:

我正在尝试获取正确的语法以从 mysql 数据库中提取 url 和关联的标签并将它们放入 href 中。我只是没有得到正确的语法。

下面的代码获取链接,但不获取随附的标签。 "$title" 不显示标签。

 <?php
        $conn=mysqli_connect("localhost", "showcase", "showcase123", "nasja723_Showcase");
        // Check connection
        if ($conn-> connect_error) {
         die ("Connection failed:". $conn-> connect_error);
        }

        $sql = "Select Title, Fname, Lname,url from Showcase";
        $result = $conn-> query($sql);
        if ($result-> num_rows > 0) {
            While ($row = $result-> fetch_assoc())  {
                echo "<tr>";
            echo "<td>",'<a href=' . $row['url'] . '>$title </a>',"</td>";  


            }
            Echo "</table>";
        }
        else {
            echo "0 result";
        }


$conn-> close();

?>

【问题讨论】:

  • 查看您从有效的数据库中获得的价值 - $row['url']。将其与没有的进行比较 - $title
  • $title 是在哪里定义的,还是您的意思是 $row['Title']

标签: php mysql href


【解决方案1】:

使用这个:

echo "<td>",'<a href=' . $row['url'] . '>'.$row['Title'].' </a>',"</td>";

$title 实际上不存在,您需要访问行中返回的“标题”列,如果存在,则不会以单引号显示,您必须使用双引号或将其连接起来.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-29
    • 2016-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 2011-07-09
    相关资源
    最近更新 更多