943,877 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 21057
  • PHP RSS
Jan 21st, 2008
0

href links with variables?

Expand Post »
I'm not entirely sure if this is actually possible. Haven't found anything yet. What I'd like to do is have a page that lists numerous articles. Then when you click on the "Read more..." link I want to go through to a template page that would pull all the info from the MySQL database for that particular artical and display it.

If this isn't possible could someone suggest something else that might work in a similar fashion.

php Syntax (Toggle Plain Text)
  1. if ($_REQUEST('is_answered') {
  2. $reward = $_POST['cookie'];
  3. $user = $reward;
  4. }
Similar Threads
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Jan 21st, 2008
0

Re: href links with variables?

Well in the database you would store the page name/page ID as well as the actual page in a largetext or memo field. When the page is requested by name/ID you would simply pull it from the database and display it, ie., <a href="page?id=25018">Read more...</a>
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Jan 21st, 2008
1

Re: href links with variables?

This is a very simple example, but you can build on it:

I am sure you know how get works, but ill put it here anyway, this link sets $_GET['article'] to 1001 on my localhost: http://localhost/testing/test07.php?article=1001
php Syntax (Toggle Plain Text)
  1. mysql_select_db("testbase") or die(mysql_error());
  2. $query=mysql_query("
  3. SELECT info
  4. FROM articles
  5. WHERE article_id='" . $_GET['article'] . "'");
  6. while($entry=mysql_fetch_array($query))
  7. {
  8. echo $entry['info'];
  9. }
  10. echo "</select>";
  11. ?>

If you need further explanation just ask
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Jan 21st, 2008
0

Re: href links with variables?

Ok, I'm not sure if I understand this correctly but let me explain a little more on what I have.

At the moment I have a page that fetches the article id($aid), article title($title) and the article content($content) and displays a short summary of the content along with the title and a "Read more..." href link for each and every article in the database. Then I have a template page that has the MySQL query that would select a single article and display the entire thing on the page. So all I really need to know is how to tie them both together so that if someone clicks on "Read more..." for a particular article it will take him/her to template.php and display the article they're looking for.

My understanding from your response's so far would be to set each href as:

html Syntax (Toggle Plain Text)
  1. <a href="template.php?aid=$aid">Read more...</a>
Last edited by Venom Rush; Jan 21st, 2008 at 10:41 am.
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Jan 21st, 2008
0

Re: href links with variables?

yes, but you would have to do that in php as $aid is a php variable, so it would be:

php Syntax (Toggle Plain Text)
  1. <?php
  2. echo "<a href='template.php?aid=" . $aid . "'>Read more...</a>";
  3. ?>

OR

PHP Syntax (Toggle Plain Text)
  1. <a href="template.php?aid=<?php echo $aid; ?>">Read more...</a>

This would mean $_GET['aid'] would be equal to $aid
Last edited by hooray; Jan 21st, 2008 at 11:00 am. Reason: added another example
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Jan 21st, 2008
0

Re: href links with variables?

Awesome...thanks so much guys....much appreciated.
Reputation Points: 18
Solved Threads: 2
Posting Whiz
Venom Rush is offline Offline
325 posts
since Oct 2007
Jan 21st, 2008
0

Re: href links with variables?

you are most welcome
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Aug 28th, 2008
0

Re: href links with variables?

Click to Expand / Collapse  Quote originally posted by hooray ...
yes, but you would have to do that in php as $aid is a php variable, so it would be:

php Syntax (Toggle Plain Text)
  1. <?php
  2. echo "<a href='template.php?aid=" . $aid . "'>Read more...</a>";
  3. ?>

OR

PHP Syntax (Toggle Plain Text)
  1. <a href="template.php?aid=<?php echo $aid; ?>">Read more...</a>

This would mean $_GET['aid'] would be equal to $aid





MMMWwwwwaaahhh!! I love you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
masala_curry is offline Offline
4 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Syntax Errors, Variables & Query, Oh my!
Next Thread in PHP Forum Timeline: flash player





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC