Jump to content

create links from table entries?


gk20

Recommended Posts

I have a table called item with fields category and item. I can display all distinct categories but I want to display them as links on my home page, so that when u click a category it displays all items in that category on a new page?

Here my code for displaying each individual category:

<?php
include 'db.inc.php';

$cats = @mysql_query("SELECT DISTINCT category from item ORDER BY category");

echo '<b>&nbsp Category List<br></b>';

while ($row = mysql_fetch_array($cats))
{
echo '<font color=red size="4">';
echo '&nbsp;&nbsp;';
echo $row['category'] . '<br/>';
echo '</font>';
}
?>

Can anyone help?
Link to comment
Share on other sites

[!--quoteo(post=356919:date=Mar 21 2006, 05:39 PM:name=gk20)--][div class=\'quotetop\']QUOTE(gk20 @ Mar 21 2006, 05:39 PM) [snapback]356919[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I have a table called item with fields category and item. I can display all distinct categories but I want to display them as links on my home page, so that when u click a category it displays all items in that category on a new page?

Here my code for displaying each individual category:

<?php
include 'db.inc.php';

$cats = @mysql_query("SELECT DISTINCT category from item ORDER BY category");

echo '<b>&nbsp Category List<br></b>';

while ($row = mysql_fetch_array($cats))
{
echo '<font color=red size="4">';
echo '&nbsp;&nbsp;';
echo $row['category'] . '<br/>';
echo '</font>';
}
?>

Can anyone help?
[/quote]
if you are trying to link them then
add two more echos inside of the while
that is
while ($row = mysql_fetch_array($cats))
{
//like file is
$link = "$row['category'] "."php"


echo '<font color=red size="4">';
echo '&nbsp;&nbsp;';
echo '<a href='$link'>';
echo $row['category'] . '<br/>';
echo '</a>';
echo '</font>';
}

i hope this will work as per your needs.

Thank you,
Karthikeyan
Link to comment
Share on other sites

I've changed the code for displaying the different categories to this:

while ($row = mysql_fetch_array($cats))
{
session_register('category');
$_SESSION['category'] = $category;

$category = $row['category'];
echo '<font color=red size="4">';
echo '&nbsp;&nbsp;';
echo '<a href="viewads.php">';

echo $row['category'] . '<br/>';
echo '</a>';
echo '</font>';
}

My page for displaying the different items is called viewads.php, i dont have any files called
"categortyname".php, just this viewads.php file. At the moment it displays all items in the database,
but I want it so that when a user clicks on a category name on the home page it will just display the items
in that particular category??

Is that possible?
Heres the relevant code from my viewads.php file:

session_register('cat');
$cat = $_SESSION['category'];

$getcats = @mysql_query("SELECT DISTINCT category from item
where category = '$cat' order by category asc");

echo '<br>';
while ($row = mysql_fetch_array($getcats))
{
echo '<b><font color=red>Category: ';
echo $row['category'];
echo '<br><br></font></b>';
$catagain = $row['category'];

$getitems = @mysql_query("SELECT itemname, cost, description, itemowner
from item
where category = '$catagain'
order by itemname asc");
.......
...... etc display results

}


But it still doesnt work!! Does anybody understand what I'm trying to say???









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.