0
I want to create a cms using PDO and I got stuck at some point
I was able to display links from the database to the index page but I wasn't able to make the links display contents when they get clicked. please can someone help me out? please I prefer pdo
10 odpowiedzi
0
its a problem with your html not pdo..
0
<?php
include 'includes/database.php';
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<section>
<?php
foreach( $pdo->query('SELECT * FROM posts') as $row){
$id = $row['post_id'];
$title = $row['post_title'];
$content = $row['post_content'];
echo "<h2><a href='index.php?p_id=$id'>$title</a></h2>";
echo "$author";
echo "content";
?>
</section>
</body>
0
the database information is below
thd table name is `posts`
post_id
post_author
post_content
0
i want to click on <h2><a href='index.php?p_id=$id'>$title</a></h2> and display the contents but it doesnt work
0
I don't understand, how can the link display only the contents when clicked?
0
Try This
<?php
include 'includes/database.php';
?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<section>
<?php
if(isset($_GET['p_id'])){
$id = $_GET['p_id'];
foreach( $pdo->query('SELECT * FROM posts WHERE id=$id') as $row){
$id = $row['post_id'];
$title = $row['post_title'];
$content = $row['post_content'];
echo "<h2><a href='index.php?p_id=$id'>'.$title.'</a></h2>";
echo $author;
echo $content;
}else{
foreach( $pdo->query('SELECT * FROM posts') as $row){
$id = $row['post_id'];
$title = $row['post_title'];
$content = $row['post_content'];
echo "<h2><a href='index.php?p_id=$id'>'.$title.'</a></h2>";
echo $author;
echo $content;
}
?>
</section>
</body>
0
it didn't work
0
do you have another idea or can you make one using pdo for me
0
use your code but change these lines with this code
echo "<h2><a href='index.php?p_id=$id'>'.$title.'</a></h2>";
echo $author;
echo $content;
0
it didn't work either