Jump to content

create a query Instead of 3 query, help me

- - - - -

  • Please log in to reply
5 replies to this topic

#1
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
hi guys

i want create a update query

this is my code, and no problem for use:





		mysql_query("UPDATE `tblhistory` SET `ouhSTATUS` = 'Pess' WHERE `ouhSELECTION` = '' AND `ouhID` = '" . $row[''] . "'");

	


		mysql_query("UPDATE `tblhistory` SET `ouhSTATUS` = 'Pess' WHERE `ouhSELECTION` = '' AND `ouhID` = '" . $row[''] . "'");


	mysql_query("UPDATE `tblhistory` SET `ouhSTATUS` = 'Ive' WHERE `ouhID` = '" . $row['ouhID'] . "'");


}


but i want create a query for up speed


i want create a query Instead of 3 query



but it have problem, please fix this query for me

thank you so much

Edited by lol33d, 04 December 2011 - 03:13 AM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
To my mind, you're making it too complicated, and you're doing some strange stuff.

1) ouhLINEID is varchar, but you want to treat it like a double. That just seems a bit odd. Floor seems likely to have unpredictable results for that.

2) Your main issue is not that you have too many queries, but that you're calling them in a loop. Using 3 queries with a better, yet simple, where clause would work fine.

3) it looks like you're setting id's to InActive, regardless of the OVER/UNDER choice.

Why not do the following?
$num = 2;
mysql_query("UPDATE `tblhistory` SET `ouhSTATUS` = 'Process' WHERE `ouhSELECTION` = 'UNDER' AND `ouhSTATUS` = 'Active' AND `ouhLINEID` in ('0.5','1.5','2.5')");

mysql_query("UPDATE `tblhistory` SET `ouhSTATUS` = 'Process' WHERE  `ouhSELECTION` = 'UNDER' AND `ouhSTATUS` = 'Active' AND `ouhLINEID` in  ('3.5','4.5')");

mysql_query("UPDATE `tblhistory` SET `ouhSTATUS` = 'InActive' WHERE  `ouhSELECTION` = 'UNDER' AND `ouhSTATUS` = 'Active'");

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
thank you WingedPanther

i need (if statement) in query

please convert my function to my query

Edited by lol33d, 04 December 2011 - 03:19 AM.


#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Why?

Seriously, is this a homework assignment, or what? Why are you worried about using 1 query instead of 3?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
lol33d

lol33d

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
is not homework, i need 1 query with if statement

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Why?

Here's the deal. The queries I gave you should add a huge speed boost, but doing conditional logic in the queries may or may not trash that. Regardless, which database type are you hitting, as the syntax would vary from one type to another.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users