Printer Friendly Version Print this thread
Email this thread to a friend eMail this thread to a friend
Related Forum Posts
  1. Best way to set up Google PPC ad groups - testing (In: Pay Per Click - Google/Yahoo & Others)
Featured Web Site Template

Hundreds More at Free Site Templates.com!

Web Site Partners
Sponsored Links
Jet City Software
 
Whos Here ?
There are 0 guests and 1 members in the forums right now.
Reflects user activity within the last 5 minutes
Moderator(s): Prowler, jcokos
Member Message

leelee700
Joined: Oct 09, 2006
# Posts: 50

View the profile for leelee700 Send leelee700 a private message

Posted: 06/24/2007 05:31 pm
Edit Message Delete Message Reply to this message

Hello everyone.

Can anyone suggest a nice, quick and easy way of counting results WITHIN a result set. For example, let's say your visitor searches for something and there are a total of 100 results. Let's say City is a variable and I'd like to the searcher to be able to see that there are, for example, 20 results in LA, 20 results in NY, 20 results in ...etc. Is there an easy way of doing this?

Thanks!



langardmicro
Joined: Mar 12, 2007
# Posts: 76

View the profile for langardmicro Send langardmicro a private message

Posted: 06/25/2007 12:17 am
Edit Message Delete Message Reply to this message

What kind of database and what language are you using for a hook?



leelee700
Joined: Oct 09, 2006
# Posts: 50

View the profile for leelee700 Send leelee700 a private message

Posted: 06/25/2007 04:31 am
Edit Message Delete Message Reply to this message

Sorry using PHP and MySQL. Thanks!



Dinkar
Moderator
Joined: Aug 12, 2001
# Posts: 4318

View the profile for Dinkar Send Dinkar a private message

Posted: 06/25/2007 10:46 am
Edit Message Delete Message Reply to this message

mysql_num_rows




langardmicro
Joined: Mar 12, 2007
# Posts: 76

View the profile for langardmicro Send langardmicro a private message

Posted: 06/25/2007 05:03 pm
Edit Message Delete Message Reply to this message

$Q1 = "SELECT city FROM TABLE WHERE ... GROUP BY city";
$CityNameArr = array();
while($row = mysql_fetch_array($Q1)){
$CityNameArr[] = $row["city"];
}
foreach($CityNameArr as $key => $CityName){
$Q2 = "SELECT * FROM TABLE WHERE city = '$CityName'";
while($row = mysql_fetch_array($Q2)){
$city = $row["city"];

}
echo"There are " . mysql_num_rows($Q2) . " results for " . $city . " .<br />";
}



leelee700
Joined: Oct 09, 2006
# Posts: 50

View the profile for leelee700 Send leelee700 a private message

Posted: 06/30/2007 12:17 pm
Edit Message Delete Message Reply to this message

thanks langardmicro. that's nice code but it won't work for my case, the search querry is much more involved.

wonder why this can't be used:

.....code...
$Res = mysql_query($Sql);
$nume = mysql_num_rows($Res);

...

if($Res)
{

while($Row = mysql_fetch_array($Res))

{

$fieldtodisplay = $Row["$field1"];
$cities = $Row["City"];

$citycount=count($cities);
echo $citycount;

or something like that? is there a simple function that can be used to just count how many times something occurs in a result set?

say, for example, the total result set is this:

Row 1: New York
Row 2: Los Angeles
Row 3: DC
Row 4: DC
Row 5: New York
Row 6: New Orleans
Row 7: Miami
Row 8: New York
Row 9: DC
Row 10: DC

To just display:
New York = 3
DC = 4
Miami = 1
Los Angeles = 1
New Orleans = 1






excell
Moderator
Joined: Mar 19, 2001
# Posts: 14502

View the profile for excell Send excell a private message

Posted: 06/30/2007 12:28 pm
Edit Message Delete Message Reply to this message

I know I don't have the answer, but thanks for asking the question - it's one I am also thinking that I need to address. What was wrong with following Dinkar's link? Did it not produce the answer?



leelee700
Joined: Oct 09, 2006
# Posts: 50

View the profile for leelee700 Send leelee700 a private message

Posted: 06/30/2007 02:49 pm
Edit Message Delete Message Reply to this message

hi excell, thanks. Dinkar's link was good but as far as i can tell it's for counting the TOTAL result set, not counting a sub-set of results. anyway im still new to php so maybe that link has the answer but it was above me for now.



Dinkar
Moderator
Joined: Aug 12, 2001
# Posts: 4318

View the profile for Dinkar Send Dinkar a private message

Posted: 06/30/2007 06:25 pm
Edit Message Delete Message Reply to this message

You need to write your own php code to count as you may do to count words in an array.



Dinkar
Moderator
Joined: Aug 12, 2001
# Posts: 4318

View the profile for Dinkar Send Dinkar a private message

Posted: 06/30/2007 06:41 pm
Edit Message Delete Message Reply to this message

Use array_count_values()



langardmicro
Joined: Mar 12, 2007
# Posts: 76

View the profile for langardmicro Send langardmicro a private message

Posted: 07/10/2007 12:13 am
Edit Message Delete Message Reply to this message

leelee700,

Well, you have two choices: You can either make more than one query to the database or you can create a bunch of multi-dimensional arrays from the results of ONE query, whatever suits you.

I say do whatever consumes the least processor resources or, barring that, whatever you feel most comfortable with.

You can either limit (a number of) SQL queries or write the code to do a bunch of array intersects and counts (on the keys or values) for ONE combined result set. You can slice 'em, dice 'em or splice 'em. I really don't know how sophisticated your application is or what you're trying to ultimately accomplish, but I'm positive that those are the only two options you have.

I don't know, when in doubt go with the Ize sisters: conceptualize, prioritize, economize, rumplestiltskinize...



You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
  1. You have not yet logged in, or registered properly as a member
  2. You are a member, but no longer have posting rights.
  3. This is a private forum, for which you do not have permissions.

If you are a recent member, it's possible that you simply have not yet confirmed your account. Please check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions contained within.

If you cannot find this message, click here to Re-Send it.

If you are still experiencing problem, please read the Login Assistance Article for some advice on what may be causing your login not to work properly.

Switch to Advanced Editor and ... Create a New Topic or Reply to this Thread

New posts Forum is locked
© 1995  ·  iWeb, Inc  ·  DBA JimWorld Productions