Variables as hyperlinks ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Variables as hyperlinks ?

Post by MiniMonty »

Hi all,

slight newb question - how do I print variables (strings) as hyperlinks ?

I have a script which lists courses that members have signed up to and prints
them as a list:

Code: Select all

 
        <?php $id = mysql_real_escape_string($id);
    $id = eregi_replace("`", "", $id);
    $query = sprintf("SELECT c.* FROM students_to_courses stc INNER JOIN courses c ON stc.course_fk = c.course_id WHERE stc.student_fk = '$id'");
    $result = mysql_query($query);
 
while ($row = mysql_fetch_assoc($result)) {
    $tutor = $row['tutor_fk'];
    $course_name = $row['course_name'];
    $course_descriptoin = $row['course_description'];
    print '<span class="orangeText">' . $course_name .  " ".  "<br>" .'</span>';
} ?>
 
the output looks like this:
Image

Question:
what do I need to add to the code to make each (orange) item in the list into a simple hyperlink ?

Best wishes
Monty
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

Where do you want the hyperlink to lead to?

Code: Select all

echo '<a href="PUT_URL_HERE" class="orangeText">' . $course_name .  ' <br /></a>';
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

Re: Variables as hyperlinks ?

Post by MiniMonty »

Thanks

I want it to lead to "student_upload.php" which is simple (even for me) !
But I also want the link to post a variable to that page in the URL. (unless there's a better way) ??

So I've been trying

Code: Select all

 
print '<a href="student_upload.php?courseName=$course_name" class="orangeText">' . $course_name .  ' <br /></a>';
 
And many other versions of it but I can't seem to find the right syntax to post a pre-declared variable - only simple strings !
i.e. blah.php?user=Tom is no problem to print on the receiving page - but how can I post a variable declared and given a value
on page 1 to page 2 ?

i.e - if on page 1 we say $frustration="deep";
what's the syntax to pass this and print it on page 2 ?
Post Reply