href links with variables?

Thread Solved

Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

href links with variables?

 
0
  #1
Jan 21st, 2008
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.

  1. if ($_REQUEST('is_answered') {
  2. $reward = $_POST['cookie'];
  3. $user = $reward;
  4. }
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,431
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 233
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: href links with variables?

 
0
  #2
Jan 21st, 2008
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>
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: href links with variables?

 
1
  #3
Jan 21st, 2008
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
  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Re: href links with variables?

 
0
  #4
Jan 21st, 2008
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:

  1. <a href="template.php?aid=$aid">Read more...</a>
Last edited by Venom Rush; Jan 21st, 2008 at 10:41 am.
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: href links with variables?

 
0
  #5
Jan 21st, 2008
yes, but you would have to do that in php as $aid is a php variable, so it would be:

  1. <?php
  2. echo "<a href='template.php?aid=" . $aid . "'>Read more...</a>";
  3. ?>

OR

  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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 260
Reputation: Venom Rush is an unknown quantity at this point 
Solved Threads: 2
Venom Rush's Avatar
Venom Rush Venom Rush is offline Offline
Posting Whiz in Training

Re: href links with variables?

 
0
  #6
Jan 21st, 2008
Awesome...thanks so much guys....much appreciated.
This user has a spatula. We don't know why, but we are afraid.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: href links with variables?

 
0
  #7
Jan 21st, 2008
you are most welcome
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1
Reputation: masala_curry is an unknown quantity at this point 
Solved Threads: 0
masala_curry masala_curry is offline Offline
Newbie Poster

Re: href links with variables?

 
0
  #8
Aug 28th, 2008
Originally Posted by hooray View Post
yes, but you would have to do that in php as $aid is a php variable, so it would be:

  1. <?php
  2. echo "<a href='template.php?aid=" . $aid . "'>Read more...</a>";
  3. ?>

OR

  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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 6969 | Replies: 7
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC