display information from url

2 posts by 2 authors in: Forums > CMS Builder
Last Post: March 7, 2012   (RSS)

By 4cdg - March 6, 2012

I have a site which i have coded the category in the url, i want to display that category on my list viewer based on what link the user visits, so if they visit products.php?category=6 the label for category 6 would show on the top of the page

If they visited products.php?category=1 it would display that label.

any suggestions

Re: [4cdg] display information from url

By Damon - March 7, 2012

Hi,

Here is some code that will do what you need:

<?php $categoryNum = @$_GET["category"]; // get the category num from the URL query ?>
<?php if($categoryNum) : ?>
<?php foreach ($newsRecords as $record): ?>
<?php if($categoryNum == $record['category']) : ?>
<h1><?php echo $record['category:label'] ?></h1>
<?php break; ?>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>


First it checks to see if is a category number in the URL query exists.

Next, it checks to see if the category number in the URL query matches a category number in the database.

And finally, if there is a match, instead of displaying the category record number, it displays the label which is the name. And uses break to only display the name once.

In the code, change $newsRecords to match what you are using.

Hope this helps! Let me know if you have any questions about this.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/