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
limit string by words??
hello all,
I was wonder if there is a function to limit a string by the number of words inste
use an array from 1 class in a second class
I have a class that adds data to an array
Then I have a second class and I need to check if t
tell csv import script to ignore blank rows?
Hi i have the below script but i get an error if a row is blank ie a return in the csv file at the e
Xacute search within SQL results
I have a query that is pulling data, and I want to return a specific value from the results of that
IP Based Cron Jobs
I run cronjobs on my website. After one of my visitors got curious and tinkered around he realized h
problems with search form numerical "between" sending by php
I am trying to display the results of a search, on a sql database, on a web page. I set up html &quo
displaying email without attracting a ton of spam
Hello,
this is maybe the wrong place to ask.
How would you display an email address on a w
Getting the full city list from maxminds geoip database
I am suprised I can't find any references to this.
I have maxminds geoip lite installed and i
Inserting a variable in a link
I have this code that I want to insert for my own variable but I have no idea how. This is what I wa
Is STL important?
I'm just starting programming and I've made it until the Standart Template Library. But the chapter