Page 1 of 1

Illegal string offset

Posted: Sat Aug 18, 2012 9:09 am
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

Re: Illegal string offset

Posted: Sat Aug 18, 2012 10:28 am
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