Jump to content

Multiple Update


Erick020

Recommended Posts

I would like to insert and then update several data at the same time in a database.

 

I have this querry I run to get the page on which I run then the "insert / update" querry:

 

$q = "select * from DATABASE_0

 

  WHERE Sold = 'NO'

  AND Zip LIKE '$Zip1$Zip2%'

  ORDER BY Date asc

  LIMIT $Leads_H ";

           

if(!($res = mysql_DB_query($DB, $q)))

          die("ERROR");

         

          $res = mysql_db_query($DB, $q);

        $numberOfRows=mysql_num_rows($res);

 

while ($i > $Leads_H) {

$Q_ID=mysql_result($res,$i,"Q_ID");

echo "<input type='hidden' name='".$r["Q_ID"]."' value=Q_ID[$i]>";

 

}

        while ($r=mysql_fetch_array($res)){ 

        $Q_ID = $_POST[Q_ID][$i];

   

        echo "<input type=hidden name=Q_ID[$i] value=".$r["Q_ID"].">

        <td align=left class=black>".$r["Name"]."</td>

        <td align=left class=black>".$r["Zip"]."</td>";

++$i;

 

}

 

echo "<a href=Command.php>ORDER</a>";

 

NOTE : THIS WORKS OK, I GET  <input type=hidden name=Q_ID[0] value=6>

<input type=hidden name=Q_ID[1] value=9>

<input type=hidden name=Q_ID[2] value=17>

 

On the next script (Command.php) I run:

 

$q ="insert into DATABASE_1 (Company_Name, A2, A3) values ('$Company_Name', '$A2', '$A3')";

 

and then I need to update an other table:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

 

WHERE

 

'Q_ID[$i]' = 'Q_ID[$i]' LIMIT $Leads_H";echo $q;

 

while ($r=mysql_fetch_array($res)){ 

        $Q_ID = $_POST[Q_ID][$i];

        }

 

BUT THIS PART DOE NOT WORK... I FOR SURE MISS SOMETHING !.... BUT WHAT?!

 

I appreciate your help....  thanks a lot...

Cheers,

Erick

Link to comment
https://forums.phpfreaks.com/topic/52156-multiple-update/
Share on other sites

hmmm....maybe take the single quote off of the column name:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

 

  WHERE

 

  'Q_ID[$i]' = 'Q_ID[$i]' LIMIT $Leads_H";

 

...so then you would have:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

 

  WHERE

 

  Q_ID[$i] = 'Q_ID[$i]' LIMIT $Leads_H";

 

...what kind of errror are you getting? I wish I knew what your program is doing b/c it seems as though there is a more efficient way to accomplish what you are trying to do..... :-\

Link to comment
https://forums.phpfreaks.com/topic/52156-multiple-update/#findComment-257321
Share on other sites

hmmm....maybe take the single quote off of the column name:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

   

   WHERE

   

   'Q_ID[$i]' = 'Q_ID[$i]' LIMIT $Leads_H";

 

...so then you would have:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

   

   WHERE

   

   Q_ID[$i] = 'Q_ID[$i]' LIMIT $Leads_H";

 

...what kind of errror are you getting? I wish I knew what your program is doing b/c it seems as though there is a more efficient way to accomplish what you are trying to do..... :-\

 

Thank you for your answer.

Well, I don't get any error, but the update is done as follow:

This querry updates the first X rows ($Leads_H) in the table... without considering the ID of the chosen data.

Once it's done, if I run the script again... it won't update any more unless the LIMIT is higher, for exemple 4 instead of 3 and it will update the fourth row.... but still the wrong one.

 

It seems it doesn't recognize the ID of Q_ID

In my exemple:

<input type=hidden name=Q_ID[1] value=9>

<input type=hidden name=Q_ID[2] value=17>

it supposes to update Q_ID where the ID is 9 and 17

 

I hope I have been clear enough... thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/52156-multiple-update/#findComment-257389
Share on other sites

hmmm....maybe take the single quote off of the column name:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

   

   WHERE

   

   'Q_ID[$i]' = 'Q_ID[$i]' LIMIT $Leads_H";

 

...so then you would have:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

   

   WHERE

   

   Q_ID[$i] = 'Q_ID[$i]' LIMIT $Leads_H";

 

...what kind of errror are you getting? I wish I knew what your program is doing b/c it seems as though there is a more efficient way to accomplish what you are trying to do..... :-\

 

Thank you for your answer.

Well, I don't get any error, but the update is done as follow:

This querry updates the first X rows ($Leads_H) in the table... without considering the ID of the chosen data.

Once it's done, if I run the script again... it won't update any more unless the LIMIT is higher, for exemple 4 instead of 3 and it will update the fourth row.... but still the wrong one.

 

It seems it doesn't recognize the ID of Q_ID

In my exemple:

<input type=hidden name=Q_ID[1] value=9>

<input type=hidden name=Q_ID[2] value=17>

it supposes to update Q_ID where the ID is 9 and 17

 

I hope I have been clear enough... thanks for your help

 

Is anybody there who can help me please?

Link to comment
https://forums.phpfreaks.com/topic/52156-multiple-update/#findComment-262015
Share on other sites

hmmm....maybe take the single quote off of the column name:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

   

   WHERE

   

   'Q_ID[$i]' = 'Q_ID[$i]' LIMIT $Leads_H";

 

...so then you would have:

 

$q = "update DATABASE_0 set Sold='YES',Company_Name='$A'

   

   WHERE

   

   Q_ID[$i] = 'Q_ID[$i]' LIMIT $Leads_H";

 

...what kind of errror are you getting? I wish I knew what your program is doing b/c it seems as though there is a more efficient way to accomplish what you are trying to do..... :-\

 

Thank you for your answer.

Well, I don't get any error, but the update is done as follow:

This querry updates the first X rows ($Leads_H) in the table... without considering the ID of the chosen data.

Once it's done, if I run the script again... it won't update any more unless the LIMIT is higher, for exemple 4 instead of 3 and it will update the fourth row.... but still the wrong one.

 

It seems it doesn't recognize the ID of Q_ID

In my exemple:

<input type=hidden name=Q_ID[1] value=9>

<input type=hidden name=Q_ID[2] value=17>

it supposes to update Q_ID where the ID is 9 and 17

 

I hope I have been clear enough... thanks for your help

 

Is anybody there who can help me please?

 

No one can help me?

Link to comment
https://forums.phpfreaks.com/topic/52156-multiple-update/#findComment-262131
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.