Jump to content

Error, trying to count rows.. HELP PLEASE =]


jigsawsoul

Recommended Posts

any help would be great thanks :)

 

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 'WHERE categories_id = '1'' at line 1

 

<?php

$result = "SELECT * FROM categories";
$result = mysql_query ($result) or die (mysql_error());
while($row = mysql_fetch_assoc($result)) 
{	

	$id = $row['id'];

	$query = "SELECT categories_id, COUNT(categories_id) FROM products GROUP BY categories_id WHERE categories_id = '$id'";
	$query = mysql_query ($query) or die (mysql_error());
	$number = mysql_fetch_assoc($result);


	$categories .= '
		<li><a href="categorie.php?id='.$row['id'].'">'.$row['categorie'].' ('.$number['COUNT(categories_id)'].')</a></li>
      	';
 }

?>

<div class="CommHolder"> 
<h1>Categories</h1> 
<div class="categories"> 
    	<ul> 
    	  <?php echo $categories ?>
    	</ul> 
</div> 
</div>

Link to comment
https://forums.phpfreaks.com/topic/196369-error-trying-to-count-rows-help-please/
Share on other sites

Doesn't work the result i get is;

 

Mac Laptops ()

PC laptops ()

 

When i should have

 

Mac Laptops (1)

Mac Desktops (2)

PC Laptops (1)

PC Desktops (2)

 

anyone know where i going wrong or if i'm doing this write  :shrug:

 

<?php

$result = "SELECT * FROM categories";
$result = mysql_query ($result) or die (mysql_error());
while($row = mysql_fetch_assoc($result)) 
{	

	$id = $row['id'];

	$query = "SELECT categories_id, COUNT(categories_id) FROM products WHERE categories_id = '$id' GROUP BY categories_id";
	$query = mysql_query ($query) or die (mysql_error());
	$number = mysql_fetch_assoc($result);


	$categories .= '
		<li><a href="categorie.php?id='.$row['id'].'">'.$row['categorie'].' ('.$number['COUNT(categories_id)'].')</a></li>
      	';
 }

?>

<div class="CommHolder"> 
<h1>Categories</h1> 
<div class="categories"> 
    	<ul> 
    	  <?php echo $categories ?>
    	</ul> 
</div> 
</div>

 

 

[attachment deleted by admin]

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.