Page 1 of 1

Variables as hyperlinks ?

Posted: Wed Jan 20, 2010 12:50 pm
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

Posted: Wed Jan 20, 2010 1:00 pm
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>';

Re: Variables as hyperlinks ?

Posted: Wed Jan 20, 2010 5:06 pm
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 ?