我怎样才能实现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个回答

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

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐