Help pulling in 'id' with "read more" link
Posted on
16th Feb 2014 07:03 pm by
admin
I'm trying to create snippets of my articles in the cms I'm creating, and then have them redirect to to a single
page entry of the article. Right now my snippets and "read more" links are dynamic and working fine, when I
click on the "read more" link it redirects to the 'single page entry' page, but it always pulls up the article
with id=1, even if the link is from id=23, and the adressbar reads articles.php?id=23.
How do I successfully pull up the corresponding id'd article?
any tips would be greatly appreciated!
Snippets:
Code: <?php
require("sources/connection.php");
$sql = "SELECT title, snippet, body_text, id FROM articles ORDER BY id DESC LIMIT 5" ;
$result = $conn->query($sql) or die(mysqli_error());
if($result){
while ($row = $result->fetch_object()){
echo "<h4>" . $row->title . "</h4>";
echo $row->snippet;
echo "</br>";
echo "<a href='/jquery/articles.php?id=" . "$row->id'";
echo ">< Read more ></a>";
}
}
?>
Articles:
Code: <?php
require("sources/connection.php");
$sql = "SELECT title, body_text, id FROM articles LIMIT 1" ;
$result = $conn->query($sql) or die(mysqli_error());
if($result){
$row = $result->fetch_object();
echo "<h4>" . $row->title . "</h4>";
echo $row->body_text;
}
?>
SQL:
Code: CREATE TABLE IF NOT EXISTS `articles` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`rel_id` int(20) NOT NULL,
`title` varchar(255) NOT NULL,
`snippet` longtext NOT NULL,
`body_text` longtext NOT NULL,
`who_id` varchar(50) NOT NULL,
`timestamp` int(20) NOT NULL,
`url` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
Thanks in advance!
No comments posted yet
Your Answer:
Login to answer
241
44
Other forums
user administration
Dear @all,
what I have to do to set the user defaults for new users. At the moment I woul
Change Web page language
i doing this thing first time but i dont find any suitable solution for it. On the demand of user. I
Problem writing URL into database
How would I write this into the database?
<?php echo "http://".$_SERVER['SER
how to timeout $doc = new DOMDocument()->load($url)
I am currently using this $doc->load($url) to fetch an rss feed.
If a feed takes long than
Passing JS to PHP
So I have the following
Code: <?php
getdetails(?><script type="text/
why preg_match_all does not return the number of matches
My regex looks like
X[^x{4e00}-x{9fa5}]*Y
(where X and Y are two Chinese characters)
session_destroy();
new to php
I have a simple login and am trying to write a logout.
I set a $_SESSION var to 1 i
Am I setting up my sites oldschool?
Ok,
When I create a site I open a basic template that I have created that consists of a css f
Security Exception on pages using AJAX
I am getting the exception: attempted to perform an operation not allowed by the security policy on
How to get all server headers like Live http Headers does
Hey all, like many of you I use the Firefox addon "Live http Headers". I'm trying to write