Jump to content

Correct Syntax to Create Dynamic URL


Bopo

Recommended Posts

Hi

 

Basically I'm getting closer to making this work, however I just can't find any example that generates an URL the way I am doing, therefore I just can't get the syntax correct as I'm just guessing, the problem is the 'print' line, but I will post all the PHP for the page anyway

 

<?php

include('blogconnect.php');

$sql = "SELECT * FROM blogposts ORDER BY id DESC LIMIT 0, 3;";
$query = mysql_query($sql, $connect);
while ($row = mysql_fetch_assoc($query)) {
  echo 'CHUNK OF DATA:<br />';
  print "<a href="www.website.com/my_category_pages.php?category=".$row['category']. ">" .$row['category'].  "</a>"";
  echo $row['id'].'<br />';
  echo $row['author'].'<br />';
  echo $row['post'].'<br />';
//  echo $row['category'].'<br />';
}

?>

 

Okay and say I get this working, when the user clicks the link, should it forward them to another page, and pass the $row['category'] value to the page, which is used in a sql query to generate the content for the page? any info appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/150720-correct-syntax-to-create-dynamic-url/
Share on other sites

Your main issues is that you use double quotes to start the string for the print, and then within the link, you use double quotes again, change it to this:

print '<a href="www.website.com/my_category_pages.php?category=' . $row['category'] . '">' . $row['category'] . '</a>';

 

And for your other question, when it loads up my_category_pages.php, you'll need to get the category value by using $_GET. Example:

$categoryValue = $_GET['category'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.