Jump to content

number of idems for each category


CodyNPaige

Recommended Posts

hey every one

I'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

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";
?>
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 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 query
SELECT count(*) FROM link WHERE catalogid= GROUP BY catalogid
failed with this error
You 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.