This is what I'd do:
$sql = "SELECT disinct category FROM article ORDER BY category";
$r = mysql_query($sql);
while($cat = mysql_fetch_array($r))
{
$id = $cat['id'];
$sql = "SELECT * FROM article WHERE category='$id'";
$x = mysql_query($sql);
while($row =
I am trying to make a catagory list that displays a distinct catagory, and
then listing titles under that catagory.
Unfortunatly all the data is in one table, and the catagory field is not set
catagories, so there is duplicates in that field.
The code so far is (but I am probably going about it
please try this:
-
I didn't really get what you mean, but i can see that you have a table such:
Table fields: category, fieldx, fieldy, fieldz, title
and you want to display it's data as:
category 1
title1 (belonging to cat1)
title2 (...)
title3 ()
title4 (...)
cat2
titlex
Thanks for the code. Its not doing exactly what I want, but with a little
modification is is kind of working.
The one problem is that it is putting the Title first and the catagory
second. so it is coming up with:
title1
title2
catagory
title3
title4
catagory1
and the last catagory is droping
Thanks for the code...
I got it to do what I wanted, by modifying it to this
$result = mysql_query ("SELECT * from article ORDER BY catagory");
$temp = "";
while ($r = mysql_fetch_array($result))
{
if (empty($temp)) // will be fired only once!
{
$temp = $r["catagory"]; // get
If I understand what you are looking for, this should work for you:
$indent_str = 'nbsp;nbsp;nbsp;';
$qry = 'SELECT * FROM test ORDER BY category';
$result = mysql_query($qry);
$current_category = "";
while ($r = mysql_fetch_array($result)){
if ($r['category'] $current_category){
Thanks man, this works great...
"Basil Groman" [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
If I understand what you are looking for, this should work for you:
$indent_str = 'nbsp;nbsp;nbsp;';
$qry = 'SELECT * FROM test ORDER BY category';
$result =
7 matches
Mail list logo