$courses_taken=$row['course_id'];
<a href="course.php?course_id=$courses_taken"></a>
As you can see from above code, i'm taking a variable and passing it in query string, but this method is wrong.
How can i pass a variable in query string, as each user will have opted for different courses, thus they will have different course_id.
Is there a way to do it?
asked Oct 24, 2013 at 3:56
3 Answers 3
<?php
$courses_taken=$row['course_id'];
?>
<a href="course.php?course_id=<?php echo $courses_taken; ?>"></a>
answered Oct 24, 2013 at 4:54
You need an echo
statement, and then interpolate the variable inside the string.
$courses_taken = $row['course_id'];
echo "<a href='course.php?course_id=$courses_taken'>click here</a>";
answered Oct 24, 2013 at 3:58
-
I'm sure this works, but another answers is more suitable for me.Siddharth Patel– Siddharth Patel2013年10月24日 16:46:28 +00:00Commented Oct 24, 2013 at 16:46
Try this:
You are not using php tag to pass php variable in your anchor tag.
Do it like this:
<a href="course.php?course_id=<?= $courses_taken; ?>"></a>
- Thanks
answered Oct 24, 2013 at 5:13
-
He's using the "short open tags" feature.
<?=
is short for<?php echo
Barmar– Barmar2013年10月24日 17:00:09 +00:00Commented Oct 24, 2013 at 17:00 -
Yes use either of method. Both are ok with this.Anand Solanki– Anand Solanki2013年10月25日 04:08:38 +00:00Commented Oct 25, 2013 at 4:08
lang-php