Re: Catagory list
| From: | elias | Date: | Sat, 31 Mar 2001 01:27:07 +0000 |
| Subject: | Re: Catagory list | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-46312@lists.php.net to get a copy of this message | ||
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
titley
titlez
that what you said, right?
okay, try 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["category"]; // get category name
echo "This is category $temp, and it's titles are as following:<br>"; //
display it
}
if ($temp != $r["category"]) // because it's sorted by category, this
method will work!
echo "This is category $temp, and it's titles are as following:<br>"; //
display it
// update last category name
$temp = $r["category"];
echo "----this is title " . $r["title"] . "<br>";
}
**
-
""Mark Bayfield"" <mbayfield@optushome.com.au> wrote in message
news:9a1u3q$k81$1@toye.p.sourceforge.net...
> 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 the wrong way, if you
> can see whats wrong with my code plase help, or point me in some
direction),
>
> $query = mysql_query("SELECT DISTINCT catagory from article order by
> catagory");
> $query2 = mysql_query ("SELECT * from article ORDER BY catagory");
>
> for ($index = 0; $index < mysql_num_rows($query); $index++) {
> $Catagory = mysql_fetch_row ($query) or die (mysql_error());
> $name1 = mysql_fetch_row ($query2) or die (mysql_error());
> $x = $name1;
> $result1 = array_unique($Catagory);
> $result = array_merge($Catagory, $name1);
>
> print ("$result1[0]<BR>");
> for ($x=0; $x == $result1[0]; $x++) {
> print (" <a
> href='update.php?passed=$name1[0]'>$name1[2]</a><br>\n");
> }
> }
>
> I am trying everything to get it do just print the following:
>
> Catagory
> title1
> title2
> Catagory1
> title3
> title4
>
> Please help me out....
>
> thanks
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>