473,396 Members | 1,838 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,396 software developers and data experts.

MySQL 2 stage queries

TheServant
1,168 Expert 1GB
Hi guys,
What I have is a tree link relationship between users on my site. It is kind of like a pyramid scheme in that if someone joins "under" you, when they get a daily update, you get 20% of their daily update.

I have a MySQL statement to this effect:
Expand|Select|Wrap|Line Numbers
  1. UPDATE users SET value=(value*factor+value)
Now to update receruiters (superior) could I have something like:
Expand|Select|Wrap|Line Numbers
  1. $rows = mysql_query("SELECT name, superior, value, factor FROM users");
  2.  
  3. while ($rows) {
  4. $row = msql_fetch_array($rows);
  5. $name = $row['name'];
  6. $superior = $row['superior'];
  7. $new_value = $row['value'] * $row['factor'] + $row['value'];
  8. $sups_value = $new_value * 0.2;
  9. mysql_query("UPDATE users SET value='$new_value' WHERE name=$name");
  10. mysql_query("UPDATE users SET value='$sups_value' WHERE name=$superior");
  11. }
However the problem is this means that there will be two UPDATEs for every row found and I was wondering if there is an easier way that anyone knows of?
Feb 5 '09 #1
2 1189
Markus
6,050 Expert 4TB
This link may be of help:

http://forums.devshed.com/mysql-help...ry-489004.html
Feb 5 '09 #2
TheServant
1,168 Expert 1GB
Cheers, some things to make my while loop slightly faster, but is there way of doing this without a while loop? As in just UPDATE-ing instead of SELECTing processing and UPDATE-ing?
Feb 5 '09 #3

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

Similar topics

4
by: Hal Halloway | last post by:
can mysql work in Windows but not Solaris? Is there any reason you can see why the fulltext php/mysql code below works OK on my win2k php4.3.6. mysql 4.1.3 pc but does *not* work when put on a...
2
by: Gary L. Burnore | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU CANNOT...
8
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU...
0
by: Plymouth Acclaim | last post by:
Hi guys, We have a problem with Dual AMD64 Opteron/MySQL 4.0.18/Mandrake 10 for a very high volume site. We are evaluating the performance on our new server AMD64 and it seems it's slow compared...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
2
by: My SQL | last post by:
Hi Is it possible for me to have the daily updation and insert queries performed on the MySQL DB saved? This will help me track when a particular record was modified in the DB. Is there...
9
by: Ben | last post by:
Hello, I'll bet this has been asked a million times but I can't seem to find a thread that gives the clear example I need. This PC has MySQL and IIS configured and running. The MySQL database is...
13
by: Ciaran | last post by:
Hi All, Is it faster to have mySql look up as much data as possible in one complex query or to have php do all the complex processing and submit lots of simple queries to the mysql database? ...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
12
by: howa | last post by:
any side effect for PHP? what do you think?
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.