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

9th Nov 2016, 2:45 PM
oghenemavo
oghenemavo - avatar
10 Respuestas
0
its a problem with your html not pdo..
9th Nov 2016, 5:09 PM
Danish Amin Dar
Danish Amin Dar - avatar
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>
9th Nov 2016, 6:31 PM
oghenemavo
oghenemavo - avatar
0
the database information is below thd table name is `posts` post_id post_author post_content
9th Nov 2016, 6:33 PM
oghenemavo
oghenemavo - avatar
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
9th Nov 2016, 6:36 PM
oghenemavo
oghenemavo - avatar
0
I don't understand, how can the link display only the contents when clicked?
9th Nov 2016, 6:43 PM
oghenemavo
oghenemavo - avatar
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>
9th Nov 2016, 6:53 PM
Danish Amin Dar
Danish Amin Dar - avatar
0
it didn't work
9th Nov 2016, 7:12 PM
oghenemavo
oghenemavo - avatar
0
do you have another idea or can you make one using pdo for me
9th Nov 2016, 7:12 PM
oghenemavo
oghenemavo - avatar
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;
9th Nov 2016, 7:14 PM
Danish Amin Dar
Danish Amin Dar - avatar
0
it didn't work either
9th Nov 2016, 7:17 PM
oghenemavo
oghenemavo - avatar