通过跟踪脚本的链接会提取正确的文章ID,错误的文章文本 [英] link going through tracking script pulls correct article id, incorrect article text

查看:64
本文介绍了通过跟踪脚本的链接会提取正确的文章ID,错误的文章文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,显示来自不同数据库表的内容.每个部分中都有一个链接,可链接到一个页面(例如,view_article.php),在该页面上显示该内容,并在其下方显示注释"部分.有问题的链接是;

I have a page that displays content from different database tables. Each of the sections has a link in it to lead to a page (view_article.php, for example) where that content is displayed with its' comment section below it. The link in question being;

'<a href="'.$site.'/views/track.php?id='.$row['article_id'].'">
<font face="arial black" color="#0000CC" size="5">
Click Here For Full Story
</font>
</a>
<hr>';  

我知道有些东西我完全不见了,因为此链接对我来说应该可以正常工作.这链接到track.php页面,该页面更新了clicks列(并以PDO形式作为我在

I know there's something I'm completely missing as this link works correctly for me as it's supposed to. This links to the track.php page which updates the clicks column (and in PDO form as an extra answer I contributed at PHP: How to increment a value in the table row to count views and to limit counts to one IP address). My Googlethons and Documentation were a bit fruitless (although, I thought a user-contributed motif was the closest to my current predicament - by dyukemedia). I just can't get the correct article text to sync up to the article id - the article id is correct in each URL access;

example.com/views/view_article.php?id=4

(例如地址栏中显示的示例文章网址)-但我的问题是,文章文本的第一行(即id = 1)是唯一从数据库中提取的行.为了我的一生,我一直无法将自己的步骤追溯到我在这里找到的建议(可能是?),以确保相对于商品ID调用正确的商品文本.即使我输入这个问题,我也会同时进行大约六个选项卡的阅读(大声笑!). git git'er完成了!感谢您的任何帮助或提前指示.

(as an example article URL shown in the address bar) - but my problem is that the FIRST row of article text (i.e. id=1) is the only one being pulled from the database. For the life of me, I haven't been able to retrace my steps to a suggestion that I found here about (possibly?) that ensures that the correct article text is called relative to the article id. Even as I type this question, I've got about six tabs of supplemental reading going on simultaneously (lol!). Gotta git 'er done! Thanks for any help or pointers in advance.

其他信息

很抱歉没有更早提供查询信息;

I apologize for not providing the query information earlier;

$stmt = $pdo->prepare("
      SELECT article_id, name, title, category, clicks 
      FROM articles 
      WHERE is_published = TRUE
      ORDER BY publish_date DESC
      ");
$stmt->bindValue(':is_published', 1);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);  

这是表articles

`article_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`name` varchar(100) NOT NULL,
`is_published` tinyint(1) NOT NULL DEFAULT '0',
`submit_date` datetime NOT NULL,
`publish_date` datetime DEFAULT NULL,
`title` varchar(255) NOT NULL,
`article_text` mediumtext,
`category` varchar(10) NOT NULL,
`clicks` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`article_id`),
KEY `user_id` (`user_id`,`submit_date`),
FULLTEXT KEY `title` (`title`,`article_text`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;  

为了阐明这一点:第一个链接示例是对名为track.php的文件的传递,该文件通过文章ID记录特定内容标题上有多少个单独的点击.从track.php开始,应该通过以下方式将观看者带到内容文章:

To clarify: the 1st link example is a pass-through to a file named track.php which records how many individual clicks-throughs there are on a particular content title via article id. From track.php, the viewer is supposed to be taken to the content article via;

header('Location: view_article.php?id='.$_GET['id']);
exit();

即使在我将$article_id替换为$_GET['id']的实验中,在每个链接悬停时,也会显示正确的商品ID,并且在选择后,地址栏中会显示正确的商品ID.当前网站首页上的所有三种情况下,只有文章内容文本是相同的(由上面列出的查询调用).

Even with an experiment where I substituted $article_id for $_GET['id'], on each link hover, the correct article id was displayed, and, when selected, the correct article id showed up in the address bar. Only the article content text was identical in all three cases currently on the site home page (called by the query listed above).

更新1

必须将主要文章导航链接更改回;

Had to change the main article navigation link back to;

<a href="'.$site.'/views/track.php?view_article.php&id='.$row['article_id'].'">  

,因为第二个文章ID之后的所有后续链接都停止更新clicks列.因此,现在我仍然处于能够更新链接点击以跟踪某篇文章内容的受欢迎程度的情况,但是无法使链接连接到正确的文章文本.我总是能够在URL地址栏中获得正确的商品ID.

as all subsequent links after the second article id stopped updating the clicks column. So, now I'm still stuck in the situation of being able to update the link clicks to track the popularity of a certain article content piece, but unable to have the link connect to the correct article text. I'm always able to get the correct article id in the URL address bar;

www.example.com/views/view_article.php?id=4

即使对track.php代码进行了多次调整,我仍然处于僵局. 任何人都能看到我要去哪里了吗?我将要求提供任何其他必要的信息.

And even with multiple tweaklings of the track.php code, I'm still at gridlock. Can anyone see where I'm going wrong? I'll include any other necessary info requested.

推荐答案

感谢@ dan08和@JiFus提示我 INDEED 塞满了SELECT查询这一事实这一切对我来说都是很糟糕的-几乎花了一天半的时间才能确定我应该一直在查看view_article.php页面上的查询;

Thanks to @dan08 and @JiFus for cluing me in on the fact that it was INDEED the SELECT query that was stuffing it all up for me - too bad it took almost a day-and-a-half to ascertain that I should've been looking at the query on the view_article.php page;

$sql = "SELECT name, title, category, publish_date, clicks, article_text
        FROM articles  
        WHERE is_published = TRUE 
        ORDER BY publish_date DESC LIMIT 1";
$result = $pdo->query($sql);  

!=

$stmt = $pdo->prepare("
SELECT 
     article_id, name, title, category, clicks, article_text, publish_date 
FROM 
     articles 
WHERE 
     article_id = :article_id 
AND 
     is_published = TRUE 
ORDER BY 
     publish_date DESC 
LIMIT 1
");
$stmt->execute(array(':article_id' => $_GET['id']));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);  

我能够将链接更改回;

I was able to change the link back to;

<a href="'.$site.'/views/track.php?id='.$row['article_id'].'">  

因为在track.php中,header()将观看者发送到特定的文章ID文本URL;

since in track.php the header() sends the viewer to the particular article id text URL ;

header('Location: view_article.php?id='.intval($_GET['id']));

现在,这修复了我必须使用它的所有内容部分中的链接导航功能.有助于在正确的位置查找问题. 课程如果该语句无法执行,我将不会获得正确的文章ID文本. GRRR ... 人为错误再次发作... (大声笑!)

Now this fixes the link navigational abilities across all of the content sections I have to employ it in. Helps to find the problem in the right place. OF COURSE I'm not going to get the correct article id text if the statement isn't able to execute. GRRR...Human Error Strikes Again... (lol!)

这篇关于通过跟踪脚本的链接会提取正确的文章ID,错误的文章文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆