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

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.