dousa2794 2015-12-08 14:13
浏览 28
已采纳

我怎样才能实现Digg的克隆? [关闭]

Ι Decided to create my own clone of Digg and I wrote this little piece of code, which just display title and description.

<?php
try 
{
    $pdo = new PDO('mysql:host=localhost;dbname=informal','vad','6989');
    $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    $pdo->exec('SET NAMES "utf8"');
} catch(PDOException $e) {
    echo $e->getMessage();
}

$sql = 'SELECT title,content FROM postID';
$result = $pdo->query($sql);
while($row = $result->fetch())
{
    echo $row['title'] . "<br />";
    echo $row['content'] . "<br />";
}
?>

And I would like, that title to be a link, and when user click on that link, database could define this record and show this article in the new page. True the fact, I did it with input type = hidden, that when you click to button "open" and it shows all. I need a more flexible approach, just like in Digg.

  • 写回答

1条回答 默认 最新

  • douhuilin1152 2015-12-08 14:18
    关注

    You have to pass parameter between two pages So first of all your have to edit add link on it

    <?php
    try 
    {
        $pdo = new PDO('mysql:host=localhost;dbname=informal','vad','6989');
        $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
        $pdo->exec('SET NAMES "utf8"');
    } catch(PDOException $e) {
        echo $e->getMessage();
    }
    
    $sql = 'SELECT title,content FROM postID';
    $result = $pdo->query($sql);
    while($row = $result->fetch())
    {
        echo "<a href=anotherpage.php?id=".$row['id'].">".$row['title'] . "</a><br />";
        echo $row['content'] . "<br />";
    }
    ?>
    

    Then on the other page you have to query with your passed ID .. And then you have to fetch data with it

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题