Hello,I want to make a code to get rid of the file extention name,but when I pass value to the function, it has a error said
reset(): Passed variable is not an array or object in /home/llama/www/FunPicSite/login/PicLink2.php on line 54
Warning: Variable passed to each() is not an array or object in /home/llama/www/FunPicSite/login/PicLink2.php on line 55
here is the code:
<?php
$user="llama";
$pass="osti";
$db="funpic";
$link=mysql_connect("localhost",$user,$pass);
if(!link)
die("couldn't connect MYSQL");
mysql_select_db($db,$link)or die("couldn't open $db:".mysql_error());
$rows_per_page=10;
if(!isset($screen))
$screen=0;
$start=$screen*$rows_per_page; //setting the start point of each page
$sql="SELECT filename,name FROM PicInfo ";
$sql.="LIMIT $start,$rows_per_page";
$result=mysql_query($sql,$link);
$total_records=mysql_num_rows($result); //the number of the links
$pages=ceil($total_records/$rows_per_page); // number of pages
$rows=mysql_num_rows($result); //number of rows
while($arrayresult=mysql_fetch_array($result,MYSQL_ASSOC))
{
$var1=$arrayresult['filename'];
$var2=$arrayresult['name'];
if(empty($var2))
{settype($var1,"string");
$var2=makepicname($var1);
}
$adress="<a href=\"http://mili.phpwebhosting.com/~llama/FunPicSite/login/votecomment.php?screen=".$var1."\">";
$adress.="$var2</a>";
print"$adress<br>";
}
function makepicname($var1)
{
$tok = strtok($var1,".");
while ($tok !== FALSE)
{
$toks[] = $tok;
$tok = strtok(".");
}
$numoftok=count($toks);
$num=$numoftok-1;
unset($toks[$num]);
reset($toks);
while (list($k,$v) = each($toks))
{
$var+=$v;
}
return $var;
}
echo"<p><hr></p>\n";
//create a dynamic links
if($screen>0){
$url="http://mili.phpwebhosting.com/~llama/FunPicSite/login/index.php?screen=" . ($screen-1);
echo"<a href=\"$url\">Previous</a>\n";
}
for($i=0;$i<$pages;$i++){
$url="http://mili.phpwebhosting.com/~llama/FunPicSite/login/index.php?screen=" .$i;
echo "|<a href=\"$url\">$i</a>|";
}
if ($screen<$pages) {
$url="http://mili.phpwebhosting.com/~llama/FunPicSite/login/index.php?screen=" . ($screen + 1);
echo "<a href=\"$url\">Next</a>\n";
}
?>
I don't know why the $var1 can't be pass to the makepicname function,please tell me why??