Jump to content

Display number of DB results beside a link?


Solarpitch

Recommended Posts

For an example, if you look at www.menupages.ie they give you a preview of how many results are found for each link.

 

ie:

 

Ballsbridge Restaurants  (52)

Blackrock Restaurants  (17)

Clondalkin Restaurants  (18)

Clontarf Restaurants  (17)

 

How is this achieved. I take it that it must be a select count on the DB for each row but that seems pointless, is there an easy way to achieve this?

Link to comment
Share on other sites

Hi,

 

I am not too sure what you mean by this.  :) In my database say I have the following... each of which are entries of a  column called "category"

 

Drivers (68)

Woods (14)

Irons (6)

Wedges (54)

 

So I need to calculate how many times Drivers is set as the "category", how many times Woods is set as the "category" and so on...

 

Example of the table...

 

ID -------- Category -------------- Price ------------ Date

 

1              Drivers                        60                      13.09.07

2              Woods                        140                      13.09.07

3              Drivers                        60                      13.09.07

4              Drivers                        55                      13.09.07

5              Irons                          200                      13.09.07

6              Drivers                        60                      13.09.07

 

So as above would be

 

Drivers (4)

Woods (1)

Irons (1)

Wedges (0)

 

 

Hope this makes sense!  :)

 

Link to comment
Share on other sites

Ok, I've had a read over that and came up with this...

 


$query = "Select count(*) From ads Where category in ('Drivers','Woods') Group by category";
$result = mysqli_query($mysql_connect, $query) or die (mysqli_error($mysql_connect));

$query_data = mysqli_fetch_row($result);
$link1 = $query_data[0];
$link2 = $query_data[1];

echo $link1; -----> Output = 18 which is correct
echo $link2; -----> Output = 0 but should be 6

 

Maybe this is correct but I am not calling the value from the array properly?

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.