Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

PHP Help needed

AlexBarakovAlexBarakov Patron Provider, Veteran
edited August 2012 in General

Hey guys,

So I haven't done any coding in PHP the last...7 years. So I need some help with something:
I need some loop that will go through every record in a table and perform the same action for a variable on each role. I will give a simple example of what I need to do:

I have a table with the following colums: ID, A, B, C .
ID is autofilled, A and B are some variables that are already in the DB. And C will be C=A+B .
So I need some kind of a cycle that will go through each line and fill the C column.

Hope this makes sence, I tried to explain it the best i could with a simple example. I can do this with ASP.NET, however I need to do it in PHP and I am in a dead end at the moment. This should eb something incredibly simple, however I can not manage to do it correctly.

Comments

  • You could just run the following query:

    UPDATE `table_name` SET `C` = (`A`+`B`);
    

    Of course, this will have to be run again every time A or B changes in any row. Ideally, if A and B are going to change often, then C really should be calculated when you're going to use it.

    SELECT (`A`+`B`) AS `C` FROM `table_name`
    
    Thanked by 1AlexBarakov
  • AlexBarakovAlexBarakov Patron Provider, Veteran

    Oh, I was just giving an example. I need some foreach (maybe) loop that will execute a specific script for each of the lines of the database, asigning different variables values from each role. I was just giving an example with A, B and C as it is easy to understand.

  • so.... something like this?

    $items = mysql_query('SELECT * FROM table');
    while ($item = mysql_fetch_assoc($items)) {
        exec('/path/to/your/script '.$item['col1'].' '.$item['col2']);
    }
    
    Thanked by 1AlexBarakov
  • AlexBarakovAlexBarakov Patron Provider, Veteran

    Yup, that while cycle should do the trick. I will update this thread once I get this working or if I need some more help. Thanks Nick, it is apreciated :)

Sign In or Register to comment.