Jump to content


Photo

MySQL + PHP - UPDATE with do...while


  • Please log in to reply
1 reply to this topic

#1 villas

villas
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 25 February 2006 - 10:10 PM

Hi ... newbie (and diferent language) calling here please be pacient!

I need UPDATE a NEW table with data of OLD table (only 2 columns) in all table (1600 regs) comparing with another diferent column

The script was an parser error in first UPDATE nd stop.

<?php require_once('../Connections/connNOR2.php'); ?>
<?php


//----recordset  (OLD table)-------------

mysql_select_db($database_connNOR2, $connNOR2);
$query_rsREAJUSTAtudoVELHA = "SELECT * FROM tab082005_2";
$rsREAJUSTAtudoVELHA = mysql_query($query_rsREAJUSTAtudoVELHA, $connNOR2) or die(mysql_error());
$row_rsREAJUSTAtudoVELHA = mysql_fetch_assoc($rsREAJUSTAtudoVELHA);
$totalRows_rsREAJUSTAtudoVELHA = mysql_num_rows($rsREAJUSTAtudoVELHA);

//----------------------------------
$codTT=$row_rsREAJUSTAtudoVELHA['tab_cod'];
$velha_hier=$row_rsREAJUSTAtudoVELHA['tab_hier'];
//-----------------------------------

//----recordset (NEW table)---------------

mysql_select_db($database_connNOR2, $connNOR2);
$query_rsREAJUSTAtudoNOVA = "SELECT * FROM tab01022006_2 WHERE tab_cod='$codTT'";
$rsREAJUSTAtudoNOVA = mysql_query($query_rsREAJUSTAtudoNOVA, $connNOR2) or die(mysql_error());
$row_rsREAJUSTAtudoNOVA = mysql_fetch_assoc($rsREAJUSTAtudoNOVA);
$totalRows_rsREAJUSTAtudoNOVA = mysql_num_rows($rsREAJUSTAtudoNOVA);

?>
<?php do { 

// put the "hhhh" and "eeee" where value is empty.

if ($velha_hier=='')

{

UPDATE tab01022006_2 SET tab_hier='hhhh',qtde_emb='eeee';  // <---PARSE ERROR ??

} else {

// put the OLD value in a NEW table

UPDATE tab01022006_2 SET tab01022006_2.tab_hier=$row_rsREAJUSTAtudoVELHA['tab_hier'], qtde_emb=$row_rsREAJUSTAtudoVELHA['qtde_emb'];

}
?>

<?php } while ($row_rsREAJUSTAtudoNOVA = mysql_fetch_assoc($rsREAJUSTAtudoNOVA)); ?>

<?php 
mysql_free_result($rsREAJUSTAtudoVELHA);
mysql_free_result($rsREAJUSTAtudoNOVA);

?>

Thanks and sory about the english


Villas

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 26 February 2006 - 06:41 AM

I see SQL code outside of quotes (i.e. in raw PHP), and not being ever sent to the server. That's bound to be the problem.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users