Re: Catagory list

From: Date: Sat, 31 Mar 2001 05:13:44 +0000
Subject: Re: Catagory list
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-46434@lists.php.net to get a copy of this message
Thanks man, this works great... "Basil Groman" <basil@groman.com> wrote in message news:4.3.2.7.2.20010330211415.0290f2a8@groman.com... > 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){ > //first time category > $current_category = $r['category']; > printf("<b>%s</b><br>\n",$current_category); > } > //Now just print the title in this row > > printf("$indent_str<i>%s</i><br>\n",$r['title']); > } > > basil > > At 11:58 AM 3/31/2001 +1000, Mark Bayfield wrote: > >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 off. I have modified the code as such (if > >you can help so that the catagory is first and the titles second it would be > >a great help): > > > >$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 category name > > // echo "This is category <b>" . $temp ."</b>, and it's > > titles are as > >following:<br>"; //display it > > // echo "----this is title <a href='update.php?passed=". > > $r["id"] > >."'><b>" . $r["title"] . > >"</b></a><br>"; > > } > > > > if ($temp != $r["catagory"]) // because it's sorted by category, this > >method will work! > > echo "This is category <b>" . $temp. "</b>, and it's > > titles are as > >following:<br>"; //display it > > // update last category name > > > > $temp = $r["catagory"]; > > // echo "This is category <b>" . $temp. "</b>, and it's > > titles are as > >following:<br>"; > > echo "----this is title <a href='update.php?passed=". > > $r["id"] ."'><b>" . > >$r["title"] . "</b></a><br>"; > > > >} > > > > > > > >""elias"" <elias_bachaalany@yahoo.com> wrote in message > >news:9a246s$mcv$1@toye.p.sourceforge.net... > > > 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 ("&nbsp;&nbsp;&nbsp;&nbsp;<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 > > > > > > > > > > > > > > > > -- > > > 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 > > > > > > > > > > >-- > >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 > > > -- > 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 >

« previous php.general (#46434) next »