473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

my code works slow. need some other logic

Hi all,

I have given my code here and it's updating the database slowly.
Can you give me some other logic.

comparing talble has 3million rows. i shoud update 1million rows.
it's taking 4 seconds to load one row..it's very slow.

please help me


[PHP]<?php
mysql_connect("localhost", "root", "sudr");
mysql_select_db("adsd");
$query_1 = "select ID from al_ao";
$result_1 = mysql_query($query_1);
while($row = mysql_fetch_array($result_1)) {
$zinc_id = $row['ZincID'];
$query_2 = "select Mwt, Xlogp, apol, pol, donors, acceptor, psa, netcharge, rb, smiles from tproperty where zincId = '$zinc_id'";
$result_2 = mysql_query($query_2);
while($row1 = mysql_fetch_array($result_2)) {
$query_3 = "update al_ao set Mwt='$row1[Mwt]', Xlogp='$row1[Xlogp]', Apol='$row1[apol]', Pol='$row1[pol]', Donor='$row1[donors]', Acceptor='$row1[acceptor]', Psa='$row1[psa]', Netcharge='$row1[netcharge]', Rb='$row1[rb]', Smiles='$row1[smiles]' where ZincID = '$zinc_id'";
mysql_query($query_3) or die("couldn't insert values");
}
}
?>[/PHP]
Jan 23 '07 #1
3 1116
ronverdonk
4,258 Expert 4TB
First that springs up is that you select field ID but fetches the data from field zincID. Must be a typo.

Secondly, you did not specify if there are any indexes used and, if so, on which columns.

Thirdly, have you ever investigated the use of the JOIN to get it together?

Ronald :cool:
Jan 23 '07 #2
Motoma
3,237 Expert 2GB
Hi all,

I have given my code here and it's updating the database slowly.
Can you give me some other logic.

comparing talble has 3million rows. i shoud update 1million rows.
it's taking 4 seconds to load one row..it's very slow.

please help me


[PHP]<?php
mysql_connect("localhost", "root", "sudr");
mysql_select_db("adsd");
$query_1 = "select ID from al_ao";
$result_1 = mysql_query($query_1);
while($row = mysql_fetch_array($result_1)) {
$zinc_id = $row['ZincID'];
$query_2 = "select Mwt, Xlogp, apol, pol, donors, acceptor, psa, netcharge, rb, smiles from tproperty where zincId = '$zinc_id'";
$result_2 = mysql_query($query_2);
while($row1 = mysql_fetch_array($result_2)) {
$query_3 = "update al_ao set Mwt='$row1[Mwt]', Xlogp='$row1[Xlogp]', Apol='$row1[apol]', Pol='$row1[pol]', Donor='$row1[donors]', Acceptor='$row1[acceptor]', Psa='$row1[psa]', Netcharge='$row1[netcharge]', Rb='$row1[rb]', Smiles='$row1[smiles]' where ZincID = '$zinc_id'";
mysql_query($query_3) or die("couldn't insert values");
}
}
?>[/PHP]
I think a more advanced SQL update is necessary:
Expand|Select|Wrap|Line Numbers
  1. UPDATE tproperty s, al_ao u
  2. SET 
  3.   u.Mwt = s.Mwt,
  4.   u.Xlogp = s.Xlogp,
  5.   u.Apol = s.Apol,
  6.   u.Pol = s.Pol,
  7.   u.Donor = s.Donor,
  8.   u.Acceptor = s.Acceptor,
  9.   u.Psa = s.Psa,
  10.   u.Netcharge = s.Netcharge,
  11.   u.Rb = s.Rb,
  12.   u.Smiles = s.Smiles
  13. WHERE
  14.   tproperty.zincID = <zincid>
  15.   AND al_ao.zincID = tproperty.zincID
  16.  
Jan 23 '07 #3
ronverdonk
4,258 Expert 4TB
motoma: Thank you for helping out.

Ronald :cool:
Jan 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
3
by: Aaron | last post by:
How would code obfuscation affect performance? in .net C#
62
by: SAN3141 | last post by:
There doesn't seem to be consensus about when to put code in the database or in the middle tier. There was a long discussion about this in an Oracle newsgroup (message ID:...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
6
by: lawrence k | last post by:
The following function is way too slow. If anyone has any suggestions about how to speed it up, I'd be grateful for them. We have to call this function 36 times on one page, and I think each time...
5
by: shuisheng | last post by:
Dear All, I was told that unit test is a powerful tool for progamming. If I am writing a GUI code, is it possible to still using unit test? I have a little experience in using unittest++. But...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.