explode error
Posted: Mon Aug 08, 2005 8:14 am
Hi i am having trouble using the exlode function on a string and am getting the following error
Warning: Variable passed to each() is not an array or object
my code is as follows:
any ideas, it works if i use explode with a space; $q_array=explode(" ", $theme);
just not with the comma
thanlks
alex
feyd | we have
Warning: Variable passed to each() is not an array or object
my code is as follows:
Code: Select all
$q_array=explode(",", $theme);
$q_num=(integer)count($q_array);
related_products($q_num, $q_array);
$r = related_products($q_num, $q_array);
print_related($r);Code: Select all
function related_products($q_num, $q_array)
{
db_connect();
$result = mysql_query("Select * from activities");
$num_results = mysql_num_rows($result);
for ($c=0;$c<$num_results;$c++)
{
$relevancy = 0;
$row = mysql_fetch_object($result);
$mypage=$row->product_id;
$theme = $row->theme;
for ($d=0; $d<$q_num; $d++)
{
$relevancy+=substr_count($theme, strtolower(strip_tags($q_array[$d])));
}
if ($relevancy>0)
$res["$mypage"] = $relevancy;
}
//sort results
if(count($res)>0)
arsort ($res);
return $res;
}
function print_related($r)
{
while($element=each($r) )
{
if($c<3)
{
$act_id = $element["key"];
$row = activity_query($act_id);
$title = $row['title'];
print '<a href="activity.php?act_id='.$act_id.'" class="navlinks">'.$title.'</a><br>';
$c++;
}
}
}just not with the comma
thanlks
alex
feyd | we have
Code: Select all
tags for a reason.. please use them.[/color]