Array issues please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Array issues please

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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 ) ){
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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;
Post Reply