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 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器