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.

 

 

 

 

Link to comment
Share on other sites

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>";
}
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.