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 Like 44 Dislike
Previous forums Next forums
Other forums

update post issues
I am trying to create an update to a post function, while the update does occur, the page routing an

Post PHP form to non-existing page
The company that I work for host their PHP code on IIS on a Windows server, no Apache, so no mod_rew

parse error
On my local machine I keep getting parse error for my footer. When I put it online, it doesn't show

DateTimeZone::listIdentifiers headache
http://php.net/manual/en/datetimezone.listidentifiers.php


So the documentation states tha

my login script page is not working on remote computers
hi my login is working on my computer, but when i tried 2 computers from 2 different locations, they

How to file_get_contents when login required?
Hello!

I am trying to read data from a page that you have to be logged into to view, I am try

Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t

HTML form problem
Ive made a form to that i want to send to my email via PHP. but when it send only the name's etc sen

Taking an HTML form and a PHP program and making it into one working file.
Hello,

So I would like to display everything INSIDE a specific directory. In other words, I

Date help - fetch dates for Mondays between xxx and yyy?
Does anyone know the best way to do this? I have two dates, say:

2010-01-26 and 2010-05-30

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash