Making links in PHP
Moderator: General Moderators
Making links in PHP
Hi,
I am just two months old working with php. I need a help for a php code. I have a script extracting the first 100 characters from a message stored in mysql database and that was sent by a visitor to my website. I only want to display those 100 characters so that I can link it to the full artice by clicking it or adding something like "Read More" in front of it.
Writing the extraction of those first 100 characters was easy with the extract command, but how do I create then the link to the full article sitting in the Mysql database so that by clicking on that link, I may be able to read the rest of the article?
Kind regards,
Darius B
I am just two months old working with php. I need a help for a php code. I have a script extracting the first 100 characters from a message stored in mysql database and that was sent by a visitor to my website. I only want to display those 100 characters so that I can link it to the full artice by clicking it or adding something like "Read More" in front of it.
Writing the extraction of those first 100 characters was easy with the extract command, but how do I create then the link to the full article sitting in the Mysql database so that by clicking on that link, I may be able to read the rest of the article?
Kind regards,
Darius B
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Hello,
I am talking about all articles that would come from the MySQL database to be displayed on a webpage. So, I mean, to reference all articles with a certain length (for instance the first 100 characters of an article)on a web page with a "Read More" link to view the rest of the articles stored in the database.
I would like to open the article on the same page.
As stated in my original post, I was able to write the code extracting the first 100 characters of all articles that were present in my database, however I failed to write the code that would display the rest of the article by clicking the "Read More" link . I hope that this makes sense.
Please, tell me how I would write that PHP code to do that job.
If this is not clear, consider this: You have a big text of a journal and you want that a visitor to your webpage sees a kind of a menu of what you have in your database and let him click the article in which s(he) is only interested.
Hope this is clear.
I will highly be grateful for the solution to this problem.
Kind regards,
Darius B
I am talking about all articles that would come from the MySQL database to be displayed on a webpage. So, I mean, to reference all articles with a certain length (for instance the first 100 characters of an article)on a web page with a "Read More" link to view the rest of the articles stored in the database.
I would like to open the article on the same page.
As stated in my original post, I was able to write the code extracting the first 100 characters of all articles that were present in my database, however I failed to write the code that would display the rest of the article by clicking the "Read More" link . I hope that this makes sense.
Please, tell me how I would write that PHP code to do that job.
If this is not clear, consider this: You have a big text of a journal and you want that a visitor to your webpage sees a kind of a menu of what you have in your database and let him click the article in which s(he) is only interested.
Hope this is clear.
I will highly be grateful for the solution to this problem.
Kind regards,
Darius B
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You make a link that makes use of the primary key value of the article.
For example, the page with the abridged version of the article would be like this:
And the other page would be like this:
And viola.
Be sure to validate the data from the $_GET superglobal array and all, and don't assume it exists either as I've done in this little sample.
For example, the page with the abridged version of the article would be like this:
Code: Select all
// Get the article information from the database
// Display the article you have retrieved with the "Read More" link
echo '<p>'
. $briefVersionOfArticle
. '... (<a href="article.php?id='
. (int)$articleId
. '">Read More...</a>)</p>';Code: Select all
// Get the article information from the database
mysql_query('SELECT `articleContents` FROM `articles` WHERE `id` = ' . (int)$_GET['id']);
// Display the article you have retrievedBe sure to validate the data from the $_GET superglobal array and all, and don't assume it exists either as I've done in this little sample.
scottayy | Please use
On the page that would normally serve to display the full article, the PHP code is:
Apparently I am not far from the truth since something show up even though it is always: "RESOURCE #5. I don't know what that means.
Can someone show me what should be done in order for the full article to show up when I click the READ MORE link, please?
Kind regards,
D.B
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi!
Thanks because there is a bit of improvment for my code. Indeed before when I moused over the "READ MORE"
link the article_id did not show up in the status bar but now I can see it for every "READ MORE" link.
How , trying to click that link yields no result on the full_article page because I can only see displaying:
RESOURCE #5 no matter which link I click on.
The PHP code for that page containing the links is as follows:Code: Select all
<?php include('../includes/connection.inc.php');
include('../includes/logout_script.inc.php');
// make a connection to mysql
$darconn = dbconnect('Admin');
// create SQL query
$sql =" SELECT * FROM articles ORDER BY article_id DESC";
$result = mysql_query($sql, $darconn) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if ($_GET && !$_POST) {
if (isset($_GET['article_id']) && is_numeric($_GET['article_id'])) {
$article_id = $_GET['article_id'];
}
else {
$article_id = NULL; }
}
?>Code: Select all
<?php
include('../includes/connection.inc.php');
include('../includes/logout_script.inc.php');
// create database connection
$darconn = dbConnect('Admin');
// get details of selected record
if ($_GET && !$_POST) {
if (isset($_GET['article_id']) && is_numeric($_GET['article_id'])) {
$article_id = $_GET['article_id'];
}
else {
$article_id = NULL;
header('Location: http://localhost/Darius/HTML/admin.php');
}
if ($article_id) {
$result = mysql_query("SELECT `content` FROM `articles` WHERE `article_id` = ". $_GET['article_id']); }
}
?>Apparently I am not far from the truth since something show up even though it is always: "RESOURCE #5. I don't know what that means.
Can someone show me what should be done in order for the full article to show up when I click the READ MORE link, please?
Kind regards,
D.B
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]scottayy | Please use
The PHP code retrieving the the full article in the body of the page was like this:
scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I forgot to mention the code that I put in the body of the page. For the page containing the "READ MORE" link
the ode is just as was mentioned by the previous responder:Code: Select all
<?php
// Get the article information from the database
// Display the article you have retrieved with the "Read More" link
echo '<p>'
. $briefVersionOfArticle
. '... (<a href="article.php?id='
. (int)$articleId
. '">Read More...</a>)</p>';
?>Code: Select all
<?php
echo "<p>" . $result."</p>";
// $result= mysql_query("SELECT `content` FROM `articles` WHERE `article_id` = ". $_GET['article_id']);
// From there the page displayed [b]RESOURCE id #5[/b], and I don't know what it means, please help
?>
<form>
<input name="article_id" type="hidden" value="<?php echo $row['article_id']; ?>">
</form>
</body>scottayy | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]