I have table :
=========================================================================
| id | stem_before | stem_after | stem_freq | sentence_id | document_id |
=========================================================================
| 1 | a | b | 1 | 0 | 1 |
| 2 | c | d | 1 | 0 | 1 |
| 3 | e | f | 1 | 1 | 1 |
| 4 | g | h | 1 | 2 | 1 |
| 5 | i | j | 2 | 0 | 2 |
| 6 | k | l | 1 | 0 | 2 |
=========================================================================
I want to count in 2 steps :
step one is divide 1 with the sum the value of stem_freq in every sentence_id and document_id. step two is multiplication the result of the first step with the value of stem_freq
for example :
for data with document_id = 1 and sentence_id = 0, first step: 1/(1+1) = 0.5, second step for id = 1 is 1*0.5 = 0.5. for id = 2 is 1*0.5 = 0.5.
for data with document_id = 2 and sentence_id = 0, first step: 1/(2+1) = 0.3333, second step for id = 5 is 2*0.3333 = 0.6666, for id = 6 is 1*0.3333 = 0.3333.
here’s my code :
$query = mysql_query ("SELECT sentence_id, document_id, stem_after,
stem_freq,SUM(stem_freq) as freq
FROM tb_stemming
WHERE document_id ='$doc_id'
GROUP BY(sentence_id)");
while ($row = mysql_fetch_array($query)) {
$a = $row['freq'];
$freq = $row['stem_freq'];
$tf = $freq/$a;
}
but it only gives me result of the first data in every different sentence : can you help me. thank you 🙂
Try this: