CodyNPaige Posted December 1, 2006 Share Posted December 1, 2006 hey every oneI'm trying to pull the amount of idem I have stored in each category but I can't seem to finger out the right way to do it.This is the code I have tried but no luck[code=php:0]<?php$link_query = "SELECT count(*) FROM link " . "WHERE catalogid={$row['linkid']}"; $link_result = mysql_query ($link_query); $link_row =mysql_fetch_row($link_result);?><?php print "($link_row[0])"; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/29167-number-of-idems-for-each-category/ Share on other sites More sharing options...
Psycho Posted December 1, 2006 Share Posted December 1, 2006 You should always add an error handler to your queries. Assuming that your query has the correct field names and $row['linkid'] has a value of records in your table your query would produce an error because the COUNT function requires that you use the GROUP BY clause;<?php$link_query = "SELECT count(*) FROM link " . "WHERE catalogid={$row['linkid']} GROUP BY catalogid";?> Link to comment https://forums.phpfreaks.com/topic/29167-number-of-idems-for-each-category/#findComment-133713 Share on other sites More sharing options...
CodyNPaige Posted December 1, 2006 Author Share Posted December 1, 2006 I tryed the GROUP BY catalogid"; and that didn't work Link to comment https://forums.phpfreaks.com/topic/29167-number-of-idems-for-each-category/#findComment-133732 Share on other sites More sharing options...
Psycho Posted December 2, 2006 Share Posted December 2, 2006 I forgot to include the error handling so that you can see if the query is failing. Modify your query line to this and you will see any error if there is one:[code]<?php$link_result = mysql_query ($link_query) or die ("The query<br>" . $link_query . "<br>failed with this error<br>" . mysql_error());?>[/code] Link to comment https://forums.phpfreaks.com/topic/29167-number-of-idems-for-each-category/#findComment-133743 Share on other sites More sharing options...
CodyNPaige Posted December 2, 2006 Author Share Posted December 2, 2006 [quote author=mjdamato link=topic=117048.msg477315#msg477315 date=1165017817]I forgot to include the error handling so that you can see if the query is failing. Modify your query line to this and you will see any error if there is one:[code]<?php$link_result = mysql_query ($link_query) or die ("The query<br>" . $link_query . "<br>failed with this error<br>" . mysql_error());?>[/code][/quote]I get this error ;)The querySELECT count(*) FROM link WHERE catalogid= GROUP BY catalogidfailed with this errorYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY catalogid' at line 1 Link to comment https://forums.phpfreaks.com/topic/29167-number-of-idems-for-each-category/#findComment-133760 Share on other sites More sharing options...
Psycho Posted December 2, 2006 Share Posted December 2, 2006 The catalog id in your query (i.e. $row['linkid']) has no value. Where are you setting it? Link to comment https://forums.phpfreaks.com/topic/29167-number-of-idems-for-each-category/#findComment-133870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.