php-general | 2001032
Date: 03/30/01
- Next message: Boget, Chris: "RE: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Previous message: Miles Thompson: "Re: [PHP] Problems getting php to restart samba"
- In reply to: Mark Bayfield: "[PHP] Catagory list"
- Next in thread: Mark Bayfield: "Re: [PHP] Catagory list"
- Reply: Mark Bayfield: "Re: [PHP] Catagory list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 <email protected>> wrote in message
news:9a1u3q$k81$1 <email protected>
> 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 <email protected>
> For additional commands, e-mail: php-general-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>
>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Boget, Chris: "RE: [PHP] RE: [PHP-DB] Best way to check if a query succeeded"
- Previous message: Miles Thompson: "Re: [PHP] Problems getting php to restart samba"
- In reply to: Mark Bayfield: "[PHP] Catagory list"
- Next in thread: Mark Bayfield: "Re: [PHP] Catagory list"
- Reply: Mark Bayfield: "Re: [PHP] Catagory list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

