Jump to content


Photo

create links from table entries?


  • Please log in to reply
2 replies to this topic

#1 gk20

gk20
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 21 March 2006 - 12:09 PM

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?

#2 blazing_bruce

blazing_bruce
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationIndia

Posted 21 March 2006 - 02:18 PM

[!--quoteo(post=356919:date=Mar 21 2006, 05:39 PM:name=gk20)--][div class=\'quotetop\']QUOTE(gk20 @ Mar 21 2006, 05:39 PM) View Post[/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

#3 gk20

gk20
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 22 March 2006 - 11:17 PM

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???














0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users