Page 1 of 1
Array issues please
Posted: Mon Jun 27, 2005 6:25 pm
by mjseaden
Code: Select all
$keywords = explode( ' ', $_POST['Section1'] );
echo 'Keywords To Find: '.$keywords;
$count = array( );
$totcount = array( );
while( $row3 = mysql_fetch_array( $result3 ) )
{
$i_totcount = 0;
for( $i = 0; $i < count($keywords); $i++ )
{
echo $row['BigDescription'].','.$keywords[$i];
$i_totcount = $i_totcount + substr_count( $row['DescriptionBig'], $keywords[$i] );
}
$totcount[$row['PropertyID']] = $i_totcount;
}
Hi there - can anyone tell me why this code is returning empty arrays to $totcount[]. I wish to find keywords within the database cell and record the number of 'hits' within the dynamic array. I suspect that I am not using arrays correctly - can anyone shed light on the subject?
Many thanks
Mark
Posted: Mon Jun 27, 2005 6:28 pm
by John Cartwright
You never define $row, you have however defined $row3 but only use $row
Hint:
Code: Select all
while( $row3 = mysql_fetch_array( $result3 ) ){
Posted: Mon Jun 27, 2005 6:32 pm
by djot
You should use $row3 in while() and inside for().
Also you may use in_array() for $keyword instead of that for() loop, or even better only select this single field in your sql clause, since you search in only one database fieldname, not in all of them, aren't you?
Code: Select all
$totcount[$row['PropertyID']] = $i_totcount;
seems to be wrong,
should be something like
Code: Select all
$array_index = $row3['ID'];
$totcount[$array_index] = $i_totcount;