Jump to content

Querying Queries with Slightly Different Designs?


justlukeyou

Recommended Posts

I am trying to filter a query very similiar to a blog.

 

The idea is that when someone first goes to the site it shows all the articles with a category link next to the title so someone can click on a category.  However, when they click on a category it shows all the articles but the category shows without a link so its just a piece of text.

 

I have done this however I had to add an extra page which isn't ideal. Is it possible to make a category keyword appear with a link and then without a link.

 

 

 

 

Is it possible to make a category keyword appear with a link and then without a link.

 

Of course, you would just use some if/else logic to get your code to do what you want when and where you want it to -

<?php

$selected_category = ...; // the actual selected category, gotten from however you are passing it between page requests

// your code that is looping and displaying the categories on the page
while($row = mysql_fetch_assoc($result)){
if($row['category'] == $selected_category){
	// current category is the selected one, output as text
	echo $row['category'];
} else {
	// current category is not the selected one, output as link
	echo "<a href='?cat={$row['category']}'>{$row['category']}</a>";
}
}

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.