Illegal string offset

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
macario1983
Forum Newbie
Posts: 6
Joined: Fri Aug 17, 2012 5:22 pm

Illegal string offset

Post by macario1983 »

hi, i´m try to show the register in a formatted table but is getting a error

Illegal string offset

my code is

Code: Select all

		$resultado = mysql_fetch_array($query);

		echo("<table border='5';text-align:center ");	
			echo("<thead><tr><th>Chave</th><th>Nome</th><th>Email</th><th>Telefone</th></tr></thead>");
				
				foreach($resultado as $r){
									
					$linhaFormatada = "<tr><td></td><td>%</td><td>%</td><td>%</td></tr>";
					printf($linhaFormatada,$r['nome'],$r['email'],$r['telefone']);
				}
		echo("</table>");
i get the result of the query and try to display for the user, but is geting this erros, why i should do?

thanks
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Illegal string offset

Post by social_experiment »

Illegal offset in this instance could refer to attempting to access a value in $resultado that doesn't exist, i.e $r['nome'], $r['email'], $r['telefone'].

Code: Select all

<?php
foreach($resultado as $r){
   $linhaFormatada = "<tr><td></td><td>%</td><td>%</td><td>%</td></tr>";
   printf($linhaFormatada,$r['nome'],$r['email'],$r['telefone']);
}
?>
1. What does the query that selects the data look like?
2. Can you paste the error + the line of code it refers to
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply