arrays - Getting wrong result from database - Wrong counting for a specific field in records using PHP -
arrays - Getting wrong result from database - Wrong counting for a specific field in records using PHP -
i trying count number of word "saturday" that's been stored in database records using php. it's not counting correctly.i have in column 3 records : saturday saturday sunday when print out $row['repeating'] displays records saturday saturday saturday where's counter saturday must 2 , counter sunday one.my counter not working correctly out set got counter saturday 3 , sunday 3. can't spot error. thought appreciate it.
thank
$numberofwcounters = mysqli_num_rows($result); $dementiacounter1 = 1; // count saturday. $countersaturday=0; // count sunday $countersunday=0; while( $counter <= $numberofwcounters) { if ($row['day'] ='saturday') { $countersaturday++; } if ($row['repeating'] ='sunday') { $countersunday++; } $counter++; } echo $row['repeating'] ; echo "<br />the number of saturday repeating question : " . $$countersaturday ;
you not appear iterating on result set, means looping 3 times on same row (which first in result set)
you'll have utilize mysqli_fetch or equivalent create sure access each of different results query generated.
$result->bind_result( $day, $repeating ); while( $result->fetch() ) { // in every iteration of loop, $day $row['day'] , $repeating $row['repeating'] of new row if ($day =='saturday') { $countersaturday++; } if ($repeating == 'sunday') { $countersunday++; } }
php arrays
Comments
Post a Comment