Trium918 Posted July 22, 2007 Share Posted July 22, 2007 I am trying to group topics with their categories by using the anchor link. There are only two categories called Computers and Games. There are 6 different topics. Computers have 5 while Games has only 1. The query below gathers all topics. <?php $blog_query ="Select *,DATE_FORMAT(date_posted,'%W,%d %b %Y') as thedate FROM article INNER JOIN categories ON categoryID=catid WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY)AND artchild='0' ORDER BY date_posted DESC LIMIT 10 "; $blog_articles = mysql_query($blog_query); if (mysql_error()) { die("Query failed<br />$blog_query<br />" . mysql_error()); } ?> This query is pulling the name of the categories from the database and placing them in links. This is where I am stuck. <?php $category_sql="Select * FROM categories"; $category = mysql_query($category_sql) or die(mysql_error()); $num=mysql_num_rows($category); if($num>0){ echo "<ul>"; while($row=mysql_fetch_assoc($category)){ echo "<li><a href=\"blog.php\">".$row['category']."</a></li>"; } echo "</ul>"; } ?> Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/ Share on other sites More sharing options...
Trium918 Posted July 22, 2007 Author Share Posted July 22, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-304659 Share on other sites More sharing options...
Trium918 Posted July 22, 2007 Author Share Posted July 22, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-304821 Share on other sites More sharing options...
trq Posted July 22, 2007 Share Posted July 22, 2007 You'll need to ask a decent question if you expect a decent reply. Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-304822 Share on other sites More sharing options...
Trium918 Posted July 22, 2007 Author Share Posted July 22, 2007 You'll need to ask a decent question if you expect a decent reply. I am trying to group topics with their categories by using the anchor link. I stated what I am trying to do. Stop making things so difficult "thorpe"!!!!!!!!! Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-304827 Share on other sites More sharing options...
Trium918 Posted July 23, 2007 Author Share Posted July 23, 2007 *bump* Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305773 Share on other sites More sharing options...
redarrow Posted July 23, 2007 Share Posted July 23, 2007 What are you on about? Do you mean you want a user to be able to press a sub cat name and see all those topics. Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305786 Share on other sites More sharing options...
Trium918 Posted July 23, 2007 Author Share Posted July 23, 2007 What are you on about? Do you mean you want a user to be able to press a sub cat name and see all those topics. I want to be able to select all the articles that belongs to its category similar to the link below. Blog Categories All Categories Art and Photography Automotive Blogging http://blog.myspace.com/index.cfm?fuseaction=blog.home&MyToken=8ca3e229-719f-42ab-9fbc-bc38130e3767 Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305791 Share on other sites More sharing options...
redarrow Posted July 23, 2007 Share Posted July 23, 2007 You first echo out the sub cat, Then format the sub cat with links?cmd=catname then use a select with a like to get the sub cat's displayed. is that what u want. Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305793 Share on other sites More sharing options...
Trium918 Posted July 23, 2007 Author Share Posted July 23, 2007 You first echo out the sub cat, Then format the sub cat with links?cmd=catname then use a select with a like to get the sub cat's displayed. is that what u want. I got something like that working below be I am having trouble writing a join to pull from the article table. <?php if(isset($_GET['action'])){ $action = $_GET['action']; // This is where I am having problems writing // a join. categoryID=catid $blog_query ="Select * FROM article WHERE categoryID='$action' AND artchild='0' ORDER BY date_posted DESC LIMIT 10 "; } else{ // I am trying to write a join similar to this one // WHERE categoryID=catid $blog_query ="Select *,DATE_FORMAT(date_posted,'%W,%d %b %Y') as thedate FROM article INNER JOIN categories ON categoryID=catid WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY)AND artchild='0' ORDER BY date_posted DESC LIMIT 10 "; } $category_sql="Select * FROM categories"; $category = mysql_query($category_sql) or die(mysql_error()); $num=mysql_num_rows($category); if($num>0){ echo "<ul> "; while($row=mysql_fetch_assoc($category)){ $catID = $row['catid']; echo "<li><a href=\"blog.php?action=$catID\">".$row['category']."</a></li>"; } echo "</ul>"; }} ?> Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305801 Share on other sites More sharing options...
redarrow Posted July 23, 2007 Share Posted July 23, 2007 try this ok allways backup. <?php if(isset($_GET['action'])){ $action = $_GET['action']; $blog_query ="Select * FROM article as a,category as b WHERE LIKE '%$action%' AND b.id='$action' AND catartchild='0' ORDER BY date_posted DESC LIMIT 10 "; $search_result=mysql_query($blog_query) or die("mysql_error()"); while($x=mysql_fetch_assoc($search_result)){ echo $x['what_ever']; } $category_sql="Select * FROM categories"; $category = mysql_query($category_sql) or die(mysql_error()); $num=mysql_num_rows($category); if($num > 0){ echo "<ul>"; while($row=mysql_fetch_assoc($category)){ $catID = $row['catid']; echo "<li><a href=\"blog.php?action=$catID\">".$row['category']."</a></li>"; } echo "</ul>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305811 Share on other sites More sharing options...
Trium918 Posted July 24, 2007 Author Share Posted July 24, 2007 Here is the query that I used. Your method works. Ok, now what are the advantages and disadvantages of writing a query this way? I asked because I have no knowledge of wild cards, and because the category ID is displayed in the URL. Wouldn't this be consider a security breach? I only have two categories with the numbers 3 & 4. blog.php?action=3 blog.php?action=4 <?php $blog_query ="Select * FROM article as a,categories as b WHERE categoryID LIKE '%$action%' AND b.catid='$action' AND artchild='0' ORDER BY date_posted DESC LIMIT 10 "; ?> Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305988 Share on other sites More sharing options...
teng84 Posted July 24, 2007 Share Posted July 24, 2007 this % means like any character sample %teng% will be equal to Imtengdude or its like saying any string having the word teng but if %teng that means any string ending with teng and if teng% any string beginning with thing so much to explain maybe do some research on the other wild card lol Link to comment https://forums.phpfreaks.com/topic/61173-group-topics-with-their-categories-by-using-the-anchor-link/#findComment-305990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.