Unsupported operand types in my Script who worked fine befor

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
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Unsupported operand types in my Script who worked fine befor

Post by dimitris »

My Script worked fine until i got this stupid error:Unsupported operand types in...

This scripts lists some artists and gives a link to their cds!
For debugging reasons i put an
echo"z= $z";
after if(step==0)
and while it should have an integer value, it gives the output z= Array
(!Why?) :roll:

I have to say that the first step of the code (first view of the list-5 artists)
is executed well.

The second step which allows the user to browse through pages of records now cannot be executed!

As you can easily notice the second step is a modification of the first step!

I look forward for any suggestion!

Code: Select all

<?php
if($topic=='artist'){ 	
				$id[1]='';
				$artist[1]='';
	  			$min=0;//I tried to put it also here
				
	  function displayResultsArtistIndex($result,$counter,$artist,$topic)//3eroume ari8mo eggrafwn apo to $counter
		  {
			  $min=0;
			  if($counter-5>0)
			  {$min=$counter-5;}else{$min=0;}
		  	printf("<table width=400 height=122 border=0><tr>
    <td width=100>&nbsp;</td>
    <td width=186 bgcolor=#ECE6DA><div align=left>");
	  
			 for( $i=$counter;$i>$min;$i-- )
			 {
			 printf("<p><span class=style3><a href="maincode.php?step=1&topic=artist_diskoi&artist_id=%s"><strong>%s</strong></a><br></span></p>",$artist[$i],$artist[$i]);
			 }//telos for
			 
          printf("</div></td>
			<td width=100>&nbsp;</td>
		  </tr>
		</table>");
							
				
			if($counter>=5)
			{
				printf("<br><br><strong><font color="#000000" size="2" face="Arial">&#931;&#949;&#955;&#943;&#948;&#949;&#962; &#945;&#960;&#959;&#964;&#949;&#955;&#949;&#963;&#956;&#940;&#964;&#969;&#957;: [&nbsp;&nbsp;</font></strong>");
				$x=0;
				$y=0;
				for($z=$counter;$z>0;$z-=5)
				{
					$y++;
					if($y==1)
					{
					printf("<strong><font color="#000000" size="3" face="Arial">(%s) &nbsp;&nbsp;</font><strong>", $y); //to $id einai to eidos anazitiseis, to $z einai o header pou deixnei apo poia eggrafi arxizoume
					}else{
					printf("<a href="maincode.php?step=0&z=%s&topic=%s&x=%s" style="text-decoration: none">
					<strong><font color="#000000" size="2" face="Arial">%s &nbsp;&nbsp;</font><strong>
					</a>", $z , $topic, $y , $y); //to $id einai to eidos anazitiseis, to $z einai o header pou deixnei apo poia eggrafi arxizoume
					}
				}
				printf("]");
		  	}
		}//telos function
		
		function displayResultsArtistIndex0($result,$counter,$composer,$z,$x,$topic)//3eroume ari8mo eggrafwn apo to $counter
		  {
		  echo"z= $z";
		  if($z-5>0)
		  {$min=$z-5;}else{$min=0;}
		  
			printf("<table width=400 height=122 border=0><tr>
					<td width=100>&nbsp;</td>
					<td width=186 bgcolor=#ECE6DA><div align=left>");
	  
			 for( $i=$z;$i>$min;$i-- )
			 {
			 printf("<p><span class=style3><a href="maincode.php?step=1&topic=composer_diskoi&composer_id=%s"><strong>%s</strong></a><br></span></p>",$composer[$i],$composer[$i]);
			 }//telos for
			 
          printf("</div></td>
			<td width=100>&nbsp;</td>
		  </tr>
		</table>");
		
			if($counter>=5)
			{
				printf("<br><br><strong><font color="#000000" size="2" face="Arial">&#931;&#949;&#955;&#943;&#948;&#949;&#962; &#945;&#960;&#959;&#964;&#949;&#955;&#949;&#963;&#956;&#940;&#964;&#969;&#957;: [&nbsp;&nbsp;</font></strong>");
				$y=0;
				for($z=$counter;$z>0;$z-=5)//epanaxrhsimopoihsh tou $z!!
				{
					$y++;
					if($y==$x){
					printf("<strong><font color="#000000" size="3" face="Arial">(%s) &nbsp;&nbsp;</font><strong>",$y); //to $id einai to eidos anazitiseis, to $z einai o header pou deixnei apo poia eggrafi arxizoume
					}else{
					printf("<a href="maincode.php?step=0&z=%s&topic=%s&x=%s" style="text-decoration: none">
					<strong><font color="#000000" size="2" face="Arial">%s &nbsp;&nbsp;</font>
					<strong></a>" ,$z , $topic , $y, $y ); //to $id einai to eidos anazitiseis, to $z einai o header pou deixnei apo poia eggrafi arxizoume
					}
				}
				printf("]");
		  	}
		}//telos function
		
if($step==1)//eleghos an pame gia tin prwti selida
{		
	  
  require_once ("../../w/connect.inc");
			$query = "SELECT composer FROM diskoi GROUP BY composer ";
			$result = mysql_query ($query) or die("&#913;&#948;&#965;&#957;&#945;&#956;&#943;&#945; &#949;&#954;&#964;&#941;&#955;&#949;&#963;&#951;&#962; &#949;&#961;&#969;&#964;&#942;&#956;&#945;&#964;&#959;&#962;");
		
		
		$counter=0;//metritis stis array
			while ($row = @ mysql_fetch_array($result))
			 {
			 	$counter++;
				$composer[$counter]=$row['composer'];
			 }
			 
			 displayResultsArtistIndex($result,$counter,$composer,$topic); //edw stelnoume tin pragmatiki katigoria oxi omadopoihseis
		
  
}//telos if($step==1)


if($step==0)//eleghos an pame gia polles selides
{

   require_once ("../../w/connect.inc");
			$query = "SELECT composer FROM diskoi GROUP BY composer ";
			$result = mysql_query ($query) or die("&#913;&#948;&#965;&#957;&#945;&#956;&#943;&#945; &#949;&#954;&#964;&#941;&#955;&#949;&#963;&#951;&#962; &#949;&#961;&#969;&#964;&#942;&#956;&#945;&#964;&#959;&#962;");
		
		
		$counter=0;//metritis stis array
			while ($row = @ mysql_fetch_array($result))
			 {
			 	$counter++;
				$composer[$counter]=$row['composer'];
			 }
			 
			 displayResultsArtistIndex0($id,$result,$counter,$composer,$z,$x,$topic); //edw stelnoume tin pragmatiki katigoria oxi omadopoihseis
		
			 
}//telos if($step==0)
}//telos if(topic==...
?>
Thats the error I get:

z= Array
Fatal error: Unsupported operand types in /home/.../www/music/artist.php on line 61
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Re: Unsupported operand types in my Script who worked fine b

Post by dimitris »

Thank everyone who read all these lines of code!

I've got to add that i checked the status of variable $z
and i found that it is an integer
until i called

Code: Select all

displayResultsArtistIndex0($id,$result,$counter,$composer,$z,$x,$topic);
then becomes an array
i will look if while passing values where wrong!
User avatar
dimitris
Forum Contributor
Posts: 110
Joined: Wed Jan 14, 2004 3:47 am
Location: Athens, Greece

Re: Unsupported operand types in my Script who worked fine b

Post by dimitris »

SOLVED!

I found out that i had passed an extra variable when i called the function
so the sollution is to substitute

Code: Select all

displayResultsArtistIndex0($id,$result,$counter,$composer,$z,$x,$topic);
with

Code: Select all

displayResultsArtistIndex0($result,$counter,$composer,$z,$x,$topic);
Post Reply