Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou com erros nas linhas 33,40,41,42 e 43
Só que não consegui achar o que está errado
<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bobs Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bobs Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
$orders = file("$DOCUMENT_ROOT\\Teste\\orders.txt");
$number_of_orders = count($orders);
if($number_of_orders == 0)
{
echo '<p><strong>No pending orders.
Please try again later.</strong></p>';
}
echo "<table border=1>\n";
echo '<tr><th bgcolor="CCCCFF">Order Date</th>
<th bgcolor="CCCCFF">Tires</th>
<th bgcolor="CCCCFF">Spark Plugs</th>
<th bgcolor="CCCCFF">Total</th>
<th bgcolor="CCCCFF">Address</th>
<tr>';
for($i=0; $i<$number_of_orders; $i++)
{
//divide cada linha
$line = explode( . , $orders[$i] );
//mantem somente o numero de itens selecionados
$line[1] = intval($line[1]);
$line[2] = intval($line[2]);
$line[3] = intval($line[3]);
//envia cada pedido para a saída
echo "<tr><td>$line[0]</td>
<td align="right">$line[1]</td>
<td align="right">$line[2]</td>
<td align="right">$line[3]</td>
<td align="right">$line[4]</td>
<td>$line[5]</td>
</tr>";
}
echo "</table>"
?>
</body>
</html>troca
echo "<table border=1>\n"; por echo "<table border=\"1\"><br />";
$line = explode( . , $orders[$i] ); por $line = explode( "." , $orders[$i] );
e
echo "<tr><td>$line[0]</td>
<td align="right">$line[1]</td>
<td align="right">$line[2]</td>
<td align="right">$line[3]</td>
<td align="right">$line[4]</td>
<td>$line[5]</td>
</tr>";
por echo "<tr><td>$line[0]</td>
<td align=\"right\">". $line[1] ."</td>
<td align=\"right\">". $line[2] ."</td>
<td align=\"right\">". $line[3] ."</td>
<td align=\"right\">". $line[4] ."</td>
<td>". $line[5] ."</td>
</tr>";Como Sylvio Leonel disse na linha 33 você coloca aspas para cobrir o ponto:
$line = explode( "." , $orders[$i] );
E nas linhas 40, 41, 42, 43, você pode usar aspas simples para cobrir os indicadores de alinhamento, pois se você usar as aspas normais você estará fechando o "echo" que você usou no começo.
echo "<tr><td>$line[0]</td>
<td align='right'>$line[1]</td>
<td align='right'>$line[2]</td>
<td align='right'>$line[3]</td>
<td align='right'>$line[4]</td>
<td>$line[5]</td>
</tr>";
Se você abre um echo com (") ele vai entender que o próximo (") está fechando o echo.
Só para complementar a resposta do Sylvio Leonel
Obrigado, meu código por enquanto está assim:
<?php
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>Bobs Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bobs Auto Parts</h1>
<h2>Customer Orders</h2>
<?php
$orders = file("$DOCUMENT_ROOT\\Teste\\orders.txt");
$number_of_orders = count($orders);
if($number_of_orders == 0)
{
echo '<p><strong>No pending orders.
Please try again later.</strong></p>';
}
echo "<table border=\"1\"><br />";
echo '<tr><th bgcolor="CCCCFF">Order Date</th>
<th bgcolor="CCCCFF">Tires</th>
<th bgcolor="CCCCFF">Spark Plugs</th>
<th bgcolor="CCCCFF">Total</th>
<th bgcolor="CCCCFF">Address</th>
<tr>';
for($i=0; $i<$number_of_orders; $i++)
{
//divide cada linha
$line = explode( "." , $orders[$i] );
//mantem somente o numero de itens selecionados
$line[1] = intval( $line[1] );
$line[2] = intval( $line[2] );
$line[3] = intval( $line[3] );
//envia cada pedido para a saída
echo "<tr><td>$line[0]</td>
<td align='right'>$line[1]</td>
<td align='right'>$line[2]</td>
<td align='right'>$line[3]</td>
<td align='right'>$line[4]</td>
<td>$line[5]</td>
</tr>";
}
echo "</table>"
?>
</body>
</html>
Estou recebendo estes erros:
Notice: Undefined offset: 2 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 36
Notice: Undefined offset: 3 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 37
Notice: Undefined offset: 4 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 43
Notice: Undefined offset: 5 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 44
Notice: Undefined offset: 2 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 36
Notice: Undefined offset: 3 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 37
Notice: Undefined offset: 4 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 43
Notice: Undefined offset: 5 in C:\WebServer\Apache 2\htdocs\Teste\vieworders.php on line 44
E não está exibindo certo a tabela
Alguém entendeu o problema?
Não estás escapando propriamente as aspas dentro da string.