[英]PHP read more link should redirect to same page or a new page
I am a newbie to PHP and front-end coding. 我是PHP和前端编码的新手。 I have been working on a form which displays rows of messages. 我一直在处理显示消息行的表单。 Sometimes these messages tends to be too long so I am using Read more link to limit the text display. 有时这些消息往往太长,因此我使用“阅读更多”链接来限制文本显示。 The link gets displayed for every message but when I click on the link, I would want it to either display the whole message in the same page or onto a different page. 该链接会针对每条消息显示,但是当我单击该链接时,我希望它要么将整个消息显示在同一页面上,要么显示在另一页面上。 Here is the part of the code which gets the link: 这是获取链接的代码部分:
enter code here
//message.php
while($row = mysqli_fetch_assoc($result))
{
...
echo "<tr>";
...
echo "<td>" . $row['Subject'] . "</td>";
//------- display text with read more link ------------
$string = $row['msgText'];
if (strlen($string) > 10) {
// truncate string
$stringCut = substr($string, 0, 10);
// make sure it ends in a word...
$string = substr($stringCut, 0, strrpos($stringCut, ' '))."... <a href='single.php'>More</a>";
}
echo "<td>" . $string . "</td>";
.......
}
I want the whole text to be displayed in single.php page, so how do I pass reference to this page? 我希望将整个文本显示在single.php页面中,那么如何传递对该页面的引用? Or how do I display in the same page (messages.php) atleast? 还是至少显示在同一页面(messages.php)中? Appreciate any help. 感谢任何帮助。 Thanks. 谢谢。
I would send in the message id into the links url and then re-query the database based on the id in the url. 我会将消息ID发送到链接URL中,然后根据URL中的ID重新查询数据库。
For example: 例如:
<a href='single.php?message_id='<?php echo $row['id'] ?>'>More</a>
Then you can use $_GET['message_id']
in your database query to pull out that single row and then display the message. 然后,您可以在数据库查询中使用$_GET['message_id']
提取该单行,然后显示消息。
Does this make sense? 这有意义吗? You can read more about the $_GET variable here: 您可以在此处阅读有关$ _GET变量的更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.