0

I'm new to php and i need some help.
I wrote a script that supposed to count the number of records with the same value and show them in webpage, yes it is grouping the records with the same value but it is not able to show how many records is existing. I am calling to the advance programmers here...please help or i get fired..
here is the code:

$query = "SELECT SearchString,Count(SearchID)
FROM SearchString 
GROUP BY SearchString"; 

$result = odbc_exec($conn,$query);

// Print out result
while($fetch=odbc_fetch_array($result)){

echo "There area total of ". $fetch[count($fetch)] ." Searches for ". $fetch['SearchString'] .".";
    echo "<br />";

}

and here are the results:

There area total of Searches for bcg.
There area total of Searches for BCL.
There area total of Searches for betlog.
There area total of Searches for birthday.
There area total of Searches for build.
There area total of Searches for celebrants.

which supposed to return this:

There area total of [count of records] of Searches for bcg.
There area total of [count of records] Searches for BCL.
There area total of [count of records] Searches for betlog.
There area total of [count of records] Searches for birthday.
There area total of [count of records] Searches for build.
There area total of [count of records] Searches for celebrants.

Please help or i get fired.. please im begging..

Edited by Nick Evan: Fixed formatting

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by nyler01
0

I'm not sure entirely what you're trying to accomplish, but could this work?

$query = "SELECT SearchString,Count(SearchID)
FROM SearchString 
GROUP BY SearchString"; 

$result = odbc_exec($conn,$query);

// Print out result
$i = 0;
while($fetch=odbc_fetch_array($result)){

echo "There area total of ". $fetch[$i] ." Searches for ". $fetch['SearchString'] .".";
echo "<br />";
$i++;
}

All it's doing is incrementing the value of $i each time there is a valid result. So essentially it's counting the number of valid results? Let me know if this is not what you're looking for and I will try and help

0

thanks for the help but it also did'nt work. i'm trying to count records with same values from database

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.