Echo duvida codigo

01/10/2013

0

PHP

Estou a desenvolver um placar, mais estou com grande problema em exibir no value do input textdele um , veja isso:

<input name="placar1" type="text" style="text-align:center" value="<?php echo $r['placar1'];?>" size="3" maxlength="3" />


no value desse input preciso exibir coluna e linha do banco de dados, porém só estou conseguindo usa-lo sem erro a coluna placar1, preciso que especificar que a linha base vem do coluna 1. Tipo fiz na hora de cadastrar resultados:

$cadastra = mysql_query("UPDATE upload_2 SET placar1='$placar1' WHERE jogo='1'");

esse trecho não esta sendo aceito no echo: placar1='$placar1' WHERE jogo='1'"


É isso que me resta pra finalizar o bendito placar.


<form action="" method="get" enctype="multipart/form-data">
  <table width="373" border="1" align="center" cellpadding="0" cellspacing="0">
  <?php 
  $query = mysql_query ("SELECT * FROM upload_2");
  $r = mysql_fetch_array($query);
    ?>
    
      <tr>
      <th width="18" bgcolor="#CC3300" class="JG" >1</th>
          <th width="124" align="center" valign="middle" scope="col">FLAMENGO</th>
      <th width="48" scope="col"> <input name="placar1" type="text"  style="text-align:center" value="<?php echo $r['placar1'];?>" size="3" maxlength="3"  /></th>
      <th width="48" scope="col"><input name="placar2" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th width="124" scope="col">VASCO</th>
    </tr>

Luis Sergio

Luis Sergio

Responder

Posts

01/10/2013

Joel Rodrigues

Opa, ficou bem confusa a explicação. Onde exatamente está ocorrendo erro?
Responder

01/10/2013

Luis Sergio

Opa, ficou bem confusa a explicação. Onde exatamente está ocorrendo erro?


<input name="placar1" type="text"  style="text-align:center" value="<?php echo $r['placar1'];?>



Preciso exibir no value do input o que tem na coluna placar1do banco de dados,
porém como orientar a posição do placar no banco ele deve orientar também a linha, e pra isso é preciso orientar a coluna jogo


Veja o exemplo que usei para alterar valor do placar:
$cadastra = mysql_query("UPDATE upload_2 SET  placar1='$placar1' WHERE jogo='1'");
$cadastra = mysql_query("UPDATE upload_2 SET  placar2='$placar2' WHERE jogo='1'");


Mais como estou engatinhando, não sei como proceder da mesma forma pra exibir no input text o que já tem no bando de dados.

*** A exibição do primeiro input da coluna placar1 e placar2 já está funcionando com o seguinte codigo***

<input name="placar1" type="text"  style="text-align:center" value="<?php echo $r["placar1"];?>" size="3" maxlength="3"  />

<input name="placar2" type="text"  style="text-align:center" value="<?php echo $r['placar2'];?>" size="3" maxlength="3" />


Agora não sei o que acrescentar para aparecer nos demais campos o que contem no banco de dados na coluna placar1 e placar2 a partir da segunda linha.

Fiz um vídeo da duvida:
http://www.youtube.com/watch?v=S-fJvN8pqj0


Responder

01/10/2013

Luis Sergio

Se com esse codigo consegui mostrar o placar1 e placar2 na linha 1

<input name="placar1" type="text"  style="text-align:center" value="<?php echo $r["placar1"];?>" size="3" maxlength="3"  />


Foto do bando de dados:
http://img199.imageshack.us/img199/9453/v1oc.JPG

O que devo acrescentar pra exibir as próximas linhas das repectivas colunas da tabela tabela do banco de dados?

<form action="" method="get" enctype="multipart/form-data">
  <table width="373" border="1" align="center" cellpadding="0" cellspacing="0">
  <?php 
  $query = mysql_query ("SELECT * FROM upload_2");
  $r = mysql_fetch_array($query);
    ?>
    
      <tr>
      <th width="18" bgcolor="#CC3300" class="JG" >1</th>
          <th width="124" align="center" valign="middle" scope="col">FLAMENGO</th>
      <th width="48" scope="col"> <input name="placar1" type="text"  style="text-align:center" value="<?php echo $r["placar1"];?>" size="3" maxlength="3"  /></th>
      <th width="48" scope="col"><input name="placar2" type="text"  style="text-align:center" value="<?php echo $r['placar2'];?>" size="3" maxlength="3" /></th>
      <th width="124" scope="col">VASCO</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">2</th>
      <th align="center" valign="baseline">INTER</th>
      <th><input name="placar3" type="text"  style="text-align:center" value="<?php echo $r['placar1'];?>" size="3" maxlength="3" /></th>
      <th><input name="placar4" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>FLUMINENSE</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">3</th>
      <th align="center" valign="baseline">BOTAFOGO</th>
      <th><input name="placar5" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar6" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>GRÊMIO</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">4</th>
      <th align="center" valign="baseline">ABC</th>
      <th><input name="placar7" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar8" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>PALMEIRAS</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">5</th>
      <th align="center" valign="baseline">SANTA CRUZ</th>
      <th><input name="placar9" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar10" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>BRASILIENSE</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">6</th>
      <th align="center" valign="baseline">FIGUEIRENSE</th>
      <th><input name="placar11" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar12" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>ATLÉTICO GO</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">7</th>
      <th align="center" valign="baseline">SÃO CAETANO</th>
      <th><input name="placar13" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar14" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>PAUSANDU</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">8</th>
      <th align="center" valign="baseline">SÃO PAULO</th>
      <th><input name="placar15" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar16" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>VITÓRIA</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">9</th>
      <th align="center" valign="baseline">PORTUGUESA</th>
      <th><input name="placar17" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar18" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>SANTOS</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">10</th>
      <th align="center" valign="baseline">BAHIA</th>
      <th><input name="placar19" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar20" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>PONTE PRETA</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">11</th>
      <th align="center" valign="baseline">ATLÉTICO PR</th>
      <th><input name="placar21" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar22" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>CORITIBA</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">12</th>
      <th align="center" valign="baseline">NÁUTICO</th>
      <th><input name="placar23" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar24" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>CRUZEIRO</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">13</th>
      <th align="center" valign="baseline">GOIÁS</th>
      <th><input name="placar25" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar26" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>CRICIÚMA</th>
    </tr>
    <tr>
      <th bgcolor="#CC3300" class="JG">14</th>
      <th align="center" valign="baseline">ATLÉTICO MG</th>
      <th><input name="placar27" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th><input name="placar28" type="text"  style="text-align:center" value="0" size="3" maxlength="3" /></th>
      <th>CORINTHIANS</th>
    </tr>
    <tr>
      <th> </th>
      <td colspan="4" align="center" valign="baseline"><input type="submit" name="enviar" id="button" value="Atualizar Placar" /></td>
    </tr>
  </table>
  <p> </p>
</form>
</body>
</html>


Responder

01/10/2013

Joel Rodrigues

Você vai ter que fazer um laço. Veja neste link, talvez lhe ajude: [url]http://www.homeandlearn.co.uk/php/php13p2.html[/url]
Responder

01/10/2013

Luis Sergio

Resolvido: precisava indicar que era pra coletar os dados da segunda coluna em diante, que estavam na coluna (placar1 e 2),

logo usei a coluna jogo como referencia mais uma vez .

O QUE ERA ASSIM:
<?php
  $query = mysql_query ("SELECT * FROM upload_2 ");
  $r = mysql_fetch_array($query);  
   
      ?>    


Pra mudar de coluna batou acrecentar WHERE jogo= 2 pra mudar de linha, e assim fiz pra correr todas as linhas da tabela

<?php 
  $query = mysql_query ("SELECT * FROM upload_2  WHERE jogo= 2");
  $r = mysql_fetch_array($query);  
   
  	?>    


Responder

01/10/2013

William

Dúvida sanada, estou encerrando o tópico!!!!
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar