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
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.